SDL School

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

numkeysThe 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

Read the keyboard
const bool *keys = SDL_GetKeyboardState(NULL);

See this code run in Read the keyboard. Download the full program (.zip)

Notes

In SDL2

The name is the same, but the array holds Uint8 values.

See also