Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB
Expertise: Beginner
Apr 13, 2004

Capturing Key States from a Non-active Window

Sometimes you need to determine whether a particular key is pressed or not—even though the application is not active. "GetAsyncKeyState" comes to the rescue. This function takes a virtual key code as a parameter and returns non-zero if the function succeeds.

Here's a sample app for capturing the 'F5' key. In this example, I call GetAsyncKeyState in a timer, so that it can capture the key press event.


Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Const VK_F5 = &H74

Private Sub Timer1_Timer()
    If GetAsyncKeyState(VK_F5) <> 0 Then
        Text1.Text = "F5 Pressed..."
    End If
End Sub
Sriram Swaminathan
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap