Declare Function GetKeyboardState Lib "user32.dll" (lpKeyState As Byte) As Long
GetKeyboardState retrieves the state of every key on the keyboard and places the information into an array. Each element of the 256-element array identifies information about the virtual-key whose virtual-key code matches the index of the element. If the &H1 bit is set, that key is toggled. If the &H80 bit is set, the key is currently pressed down. 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 an error occured, the function returns 0 (use GetLastError to get the error code). If successful, the function returns a non-zero value.
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.
' Set the toggle status for every key on the keyboard to "not
' toggled." This change only applies to the current thread.
Dim keystates(0 To 255) As Byte ' holds states of entire keyboard
Dim c As Integer ' counter variable
Dim retval As Long ' return value
' First, get the current state of the keyboard.
retval = GetKeyboardState(keystates(0))
' Now, loop through each element and explicitly set the toggle bit to 0.
For c = 0 To 255
' Make sure the &H1 bit is not set.
keystates(c) = keystates(c) And (Not &H1)
Next c
' Finally, set this to the current keyboard state.
retval = SetKeyboardState(keystates(0))
Go back to the alphabetical Function listing.
Go back to the Reference section index.
Last Modified: September 5, 1999
This page is copyright © 1999 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/getkeyboardstate.html