GetAsyncKeyState

  SHORT GetAsyncKeyState(nVirtKey)    
  int nVirtKey; /* virtual-key code */

The GetAsyncKeyState function determines whether a key is up or down at the time the function is called, and whether the key was pressed after a previous call to the GetAsyncKeyState function.

Parameters

nVirtKey

Specifies one of 256 possible virtual-key code values.

Return Value

The return value specifies whether the key was pressed since the last call to GetAsyncKeyState and whether the key is currently up or down. If the most significant bit is set, the key is down, and if the least significant bit is set, the key was pressed after a preceding GetAsyncKeyState call. The return value is zero if a window in another thread or process currently has the keyboard focus.

Comments

If VK_LBUTTON OR VK_RBUTTON is specified in the nVirtKey parameter, this function returns the state of the physical left or right mouse button regardless of whether the SwapMouseButton function has been used to reverse the meaning of the buttons.

An application can use the virtual key code constants VK_SHIFT, VK_CONTROL and VK_MENU as values for the nVirtKey parameter. This gives the state of the Shift, Control, or Alt keys without distinguishing between left and right. An application can also use the following virtual key code constants as values for nVirtKey in order to distinguish between the left and right instances of those keys:

VK_LSHIFT VK_RSHIFT
VK_LCONTROL VK_RCONTROL
VK_LMENU VK_RMENU

These left- and right-distinguishing constants are only exposed and available to an application when using the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.

See Also

GetKeyState, GetKeyboardState, SetKeyboardState, MapVirtualKey