How do I create shortcut key for various subroutines in my programs? It's like those you can set at the Menu Editor for menus, eg. Ctrl-A, F2, etc...
Printable View
How do I create shortcut key for various subroutines in my programs? It's like those you can set at the Menu Editor for menus, eg. Ctrl-A, F2, etc...
Code:Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Caption = KeyCode & "," & Shift
If KeyCode = vbKeyF1 And Shift = 0 Then
'F1 and no mask keys pressed
End If
If KeyCode = Asc("A") And Shift = 2 Then
'A and Ctrl pressed
End If
keys
End Sub
check out keydown event in vb-help for combining your own mask
I've tried that, but it doesn't work...
Somehow the program doesn't even repsond to the keydown event (I've tried putting a breakpoint inside Form_KeyDown). Does it have to do with the focus or something?
Oh yeah, it's the focus. Set Keypreview to true on the form, and it will catch the key events from your controls in focus too.
Works great now! Thanks a lot!