How to retrieve the state of a key?

Printer-friendly versionPDF version

bool wxGetKeyState(wxKeyCode key)

For normal keys, returns true if the specified key is currently down. For togglable keys (Caps Lock, Num Lock and Scroll Lock), returns true if the key is toggled such that its LED indicator is lit. There is currently no way to test whether togglable keys are up or down. Even though there are virtual key codes defined for mouse buttons, they cannot be used with this function currently.

To retrieve the state of all the virtual keys on windows use the Win32 API:

The GetKeyboardState function copies the status of the 256 virtual keys to the specified buffer.
::GetKeyboardState(PBYTE lpKeyState)
where lpKeyState is a pointer to the 256-byte array that receives the status data for each virtual key.