Skip to content

Latest commit

 

History

History
124 lines (103 loc) · 5.58 KB

nf-winuser-getkeyboardstate.md

File metadata and controls

124 lines (103 loc) · 5.58 KB
UID title description helpviewer_keywords old-location tech.root ms.assetid ms.date ms.keywords req.header req.include-header req.target-type req.target-min-winverclnt req.target-min-winversvr req.kmdf-ver req.umdf-ver req.ddi-compliance req.unicode-ansi req.idl req.max-support req.namespace req.assembly req.type-library req.lib req.dll req.irql targetos req.typenames req.redist ms.custom f1_keywords dev_langs topic_type api_type api_location api_name req.apiset
NF:winuser.GetKeyboardState
GetKeyboardState function (winuser.h)
Copies the status of the 256 virtual keys to the specified buffer.
GetKeyboardState
GetKeyboardState function [Keyboard and Mouse Input]
_win32_GetKeyboardState
_win32_getkeyboardstate_cpp
inputdev.getkeyboardstate
winui._win32_getkeyboardstate
winuser/GetKeyboardState
inputdev\getkeyboardstate.htm
inputdev
VS|winui|~\winui\windowsuserinterface\userinput\keyboardinput\keyboardinputreference\keyboardinputfunctions\getkeyboardstate.htm
12/05/2018
GetKeyboardState, GetKeyboardState function [Keyboard and Mouse Input], _win32_GetKeyboardState, _win32_getkeyboardstate_cpp, inputdev.getkeyboardstate, winui._win32_getkeyboardstate, winuser/GetKeyboardState
winuser.h
Windows.h
Windows
Windows 2000 Professional [desktop apps only]
Windows 2000 Server [desktop apps only]
User32.lib
User32.dll
Windows
19H1
GetKeyboardState
winuser/GetKeyboardState
c++
APIRef
kbSyntax
DllExport
User32.dll
Ext-MS-Win-NTUser-Keyboard-l1-1-0.dll
Ext-MS-Win-NTUser-Keyboard-l1-1-1.dll
api-ms-win-ntuser-ie-keyboard-l1-1-0.dll
ie_stubs.dll
ext-ms-win-ntuser-keyboard-l1-1-2.dll
Ext-MS-Win-RTCore-NTUser-Rawinput-L1-1-0.dll
MinUser.dll
GetKeyboardState
ext-ms-win-ntuser-rawinput-l1-1-0 (introduced in Windows 10, version 10.0.14393)

GetKeyboardState function

-description

Copies the status of the 256 virtual keys to the specified buffer.

-parameters

-param lpKeyState [out]

Type: PBYTE

The 256-byte array that receives the status data for each virtual key.

-returns

Type: BOOL

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

-remarks

An application can call this function to retrieve the current status of all the virtual keys. The status changes as a thread removes keyboard messages from its message queue. The status does not change as keyboard messages are posted to the thread's message queue, nor does it change as keyboard messages are posted to or retrieved from message queues of other threads. (Exception: Threads that are connected through AttachThreadInput share the same keyboard state.)

When the function returns, each member of the array pointed to by the lpKeyState parameter contains status data for a virtual key. If the high-order bit is 1, the key is down; otherwise, it is up. If the key is a toggle key, for example CAPS LOCK, then the low-order bit is 1 when the key is toggled and is 0 if the key is untoggled. The low-order bit is meaningless for non-toggle keys. A toggle key is said to be toggled when it is turned on. A toggle key's indicator light (if any) on the keyboard will be on when the key is toggled, and off when the key is untoggled.

To retrieve status information for an individual key, use the GetKeyState function. To retrieve the current state for an individual key regardless of whether the corresponding keyboard message has been retrieved from the message queue, use the GetAsyncKeyState function.

An application can use the virtual-key code constants VK_SHIFT, VK_CONTROL and VK_MENU as indices into the array pointed to by lpKeyState. This gives the status of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. An application can also use the following virtual-key code constants as indices 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 available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.

-see-also