Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer
GetAsyncKeyState determines whether a certain key is currently pressed and whether that key has been pressed since the last call to the function. This function fails if the thread calling it does not currently have the input focus.
If the function fails (if the current thread does not have the input focus), the function returns 0. If the &H8000 bit of the return value is set, the key has been pressed at least once since the last time the thread called GetAsyncKeyState. If the &H1 bit of the return value is set, the key is currently pressed down.
None.
Const VK_LSHIFT = &HA0
Const VK_RSHIFT = &HA1
Const VK_LCONTROL = &HA2
Const VK_RCONTROL = &HA3
Const VK_LMENU = &HA4
Const VK_RMENU = &HA5
' This code is licensed according to the terms and conditions listed here.
' Declarations and such needed for the example:
' (Copy them to the (declarations) section of a module.)
Public Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer
' Determine whether the Q key has been pressed or not since the last
' call to the function (assuming this example code has already been run earlier).
' The code runs when button Command1 is pressed.
Private Sub Command1_Click()
Dim keystate As Integer ' state of the Q key
' Get the state of the Q key as returned by the function.
' (vbKeyQ is a VB-defined constant for Q's virtual-key code)
keystate = GetAsyncKeyState(vbKeyQ)
' Check the &H8000 bit of the return value.
If keystate And &H8000 Then
Debug.Print "The Q key has been pressed since the last check."
Else
Debug.Print "The Q key has not been pressed since the last check."
End If
End Sub
Go back to the alphabetical Function listing.
Go back to the Reference section index.
Last Modified: July 30, 2000
This page is copyright © 2000 Paul Kuliniewicz.
Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/g/getasynckeystate.html