Completenutter2
asked on
Identifying keys that have been pressed.
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
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
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
S
ASKER
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
Thanks for the standard key bit :)
Alex
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
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
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
S
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
'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