How can I have the F9 key run a piece of code when it is pressed, regardless of where in the project the user is?
Printable View
How can I have the F9 key run a piece of code when it is pressed, regardless of where in the project the user is?
Use GetasyncKeyState API. Add the following to a Form with a Timer.
Code:Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Form_Load()
Timer1.Interval = 1
End Sub
Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyF9) Then MsgBox ("F9 was pressed")
End Sub