If i am holding down both the Down arrow key and the z key, but they control different things, how can I tell if both are down?
Printable View
If i am holding down both the Down arrow key and the z key, but they control different things, how can I tell if both are down?
You can use GetASynchKeyState:
Public Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal vKey As Long) As Integer
Use like:
Code:Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyControl) Then
If GetAsyncKeyState(vbKeyZ) Then
MsgBox "ctrl+z"
End If
End If
End Sub
Getasynckeystate isn't nessesary if you use shift/ctrl/alt + a key.
BTW, if you use getanynckeystate to get seval keypresses, put them in keydown event instead of a timer, that will save you some resources and performance.
Code:Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 90 And Shift = 2 Then MsgBox "Ctrl-Z"
End Sub