API reference / Input and time
SDL_GetKeyboardState
Function, SDL3
Gets an array that tells you which keys are down now. Use it for keys that the user holds.
Declaration
#include <SDL3/SDL.h>
const bool * SDL_GetKeyboardState(int *numkeys);Parameters
numkeys | The address of an int for the array size, or NULL. |
Return value
A pointer to an array of bool. The index is a scancode, such as SDL_SCANCODE_LEFT.
Example
const bool *keys = SDL_GetKeyboardState(NULL);See this code run in Read the keyboard. Download the full program (.zip)
Notes
- SDL owns this array, so do not free it. SDL updates it as it handles events.
- For a single press, use the key down event.
In SDL2
The name is the same, but the array holds Uint8 values.