Solved

Identifying keys that have been pressed.

Posted on 2004-07-31
8
177 Views
Last Modified: 2011-10-03
I am creating a music player. And i want to have keys associated with commands. I have 3 problems:
How to read what keys have been pressed.
How to associate key combinations with code
How to read the data when the program is not in focus (like running on the system tray or minimised)

I don't think that the first two problems are that difficult but the last one might be a little more tricky.

Thanks in adavance

Alex
0
Comment
Question by:Completenutter2
  • 5
  • 2
8 Comments
 
LVL 19

Expert Comment

by:Shauli
ID: 11684175
The rules of this site do not allow more than one question at a time. As the first two questions are related then hee you go:


'Use the keydown or keyUp events to read the keys that were pressed and to associate them with commands:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
    Case vbKeyA 'a was pressed
        'associate with a command - do your stuff
    Case vbKeyF1 'the F1 key was pressed
        'associate with another command - do the other stuff
    case .....
   
End Select
End Sub

S
0
 
LVL 19

Expert Comment

by:Shauli
ID: 11684190
ps. As per your third question. I suggest your ask it in a separate question, and explaine in more details what data you want to read, from where to to where.

S
0
 

Author Comment

by:Completenutter2
ID: 11684317
OK that sounds like it would work for standard keys but how about non-standard keys like multi media  keys on a keyboard. I've seen it in winamp.

Thanks for the standard key bit :)

Alex
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 19

Expert Comment

by:Shauli
ID: 11684511
Well, you need to know the combination fo these keys, however, here is an example:

If KeyCode = vbKeyB And (Shift And vbCtrlMask > 0) Then 'either control or shift or alt key were pressed along with the B key.
    'do your stuff
End If

S
0
 
LVL 19

Expert Comment

by:Shauli
ID: 11684518
ps. To determine if it is a shift the control or the alt key then if (Shift And vbCtrlMask)=1 (shift) 2 (control) 4 (alt).

S
0
 

Author Comment

by:Completenutter2
ID: 11684527
Would there not be a way to capture the keys pressed? I know that the stop button uses Ctrl + S but the Play/Pause button is read in winamp as Play/Pause and not a key combo.
0
 
LVL 19

Accepted Solution

by:
Shauli earned 200 total points
ID: 11684575
0
 
LVL 5

Assisted Solution

by:Barsham
Barsham earned 50 total points
ID: 11692706
You can use DirectInput Api to Read Key From Where Pressed
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question