Results 1 to 2 of 2

Thread: How can I capture a keypress from anywhere?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2000


    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?

  2. #2
    Use GetasyncKeyState API. Add the following to a Form with a Timer.
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width