Declare Function SetKeyboardState Lib "user32.dll" (lpKeyState As Byte) As Long
SetKeyboardState sets the state of every key on the keyboard. 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 considered toggled. If the &H80 bit is set, the key is considered to be currently pressed down. The keyboard information set by this function is thread-specific; its settings do not necessarily change 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))
GetKeyboardState
Keyboard
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/s/setkeyboardstate.html