GetKeyState returns the current status of one of the keys on the keyboard. This status contains two pieces of information: the key's toggle state and the key's pressed state. The information is put into the return value. The toggle state is analogous to the toggle nature of the Caps Lock, Num Lock, and Scroll Lock keys, but Windows records toggle information about every key. The toggle information is stored in bit &H80 of the return value. The pressed state is true if the key is currently being depressed. The pressed information is stored in bit &H01 of the return value. See the example for more information on how to use the return value.
Declare Function GetKeyState Lib "user32.dll" (ByVal nVirtKey As Long) As Integer
The virtual key code of the key to read the status of.
Dim keystate As Long
keystate = GetKeyState(13)
If (keystate And &H01) = &H01 Then Debug.Print "Enter key is being pressed."
If (keystate And &H80) = &H80 Then Debug.Print "Enter key is toggled."