User32GetKeyState(Int32) Method

Retrieves the status of the specified virtual key.

The status specifies whether the key is up, down, or toggled (on, off—alternating each time the key is pressed).

Definition

Namespace: DevCase.Win32.NativeMethods
Assembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[DllImportAttribute("User32.dll", SetLastError = true)]
public static short GetKeyState(
	int vKey
)

Parameters

vKey  Int32
The virtual-key code.

You can use left- and right-distinguishing constants to specify certain keys.

See Virtual-Key Codes: https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx

Return Value

Int16
If the high-order bit is 1, the key is down; otherwise, it is up.

If the low-order bit is 1, the key is toggled.

A key, such as the CAPS LOCK key, is toggled if it is turned on. The key is off and untoggled if the low-order bit is 0.

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.

Remarks

See Also