RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

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



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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.



Thanks for your registration, follow us on our social networks to keep up-to-date