devxlogo

Capturing Key States from a Non-active Window

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 IntegerPrivate Const VK_F5 = &H74Private Sub Timer1_Timer()    If GetAsyncKeyState(VK_F5) <> 0 Then        Text1.Text = "F5 Pressed..."    End IfEnd Sub
See also  How to Create and Deploy QR Codes Online: A Comprehensive Guide
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist