Declare Function GetKeyState Lib "user32.dll" (ByVal nVirtKey As Long) As Integer
GetKeyState determines the current status of a key. The function both finds whether the key is currently pressed down or not, and determines if the key is currently toggled. The keyboard information retrieved by this function is thread-specific; its information does not necessarily reflect key states pertaining to the system as a whole.
If the &H1 bit of the return value is set, the key is toggled. If the &H80 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
Example:
' Display the current status of the Enter key.
Dim keystate As Long ' receives key state
' Read the current status of the Enter key.
keystate = GetKeyState(VK_RETURN)
' Display the Enter key's toggle status.
If (keystate And &H1) = &H1 Then
Debug.Print "The Enter key is currently toggled."
Else
Debug.Print "The Enter key is not currently toggled."
End If
' Display whether the Enter key is being pressed or not.
If (keystate And &H80) = &H80 Then
Debug.Print "The Enter key is currently pressed."
Else
Debug.Print "The Enter key is currently up."
End If
GetAsyncKeyState, GetKeyboardState
Last Modified: September 4, 1999
This page is copyright © 1999 Paul Kuliniewicz. Copyright Information