---
name: "SDL_GetKeyboardState"
section: "3"
platform: "linux"
package: "libsdl3-doc"
version: "3.2.10+ds-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/SDL_GetKeyboardState"
---

# SDL\_GetKeyboardState(3)

Get a snapshot of the current state of the keyboard.

## NAME

SDL\_GetKeyboardState - Get a snapshot of the current state of the keyboard.

## HEADER FILE

Defined in SDL3/SDL\_keyboard.h

## SYNOPSIS

```
#include "SDL3/SDL.h"
```

**const bool \* SDL\_GetKeyboardState(int \*numkeys);**

## DESCRIPTION

The pointer returned is a pointer to an internal SDL array. It will be valid for the whole lifetime of the application and should not be freed by the caller.

A array element with a value of true means that the key is pressed and a value of false means that it is not. Indexes into this array are obtained by using  **SDL\_Scancode**\
  values.

Use  **SDL\_PumpEvents** () to update the state array.

This function gives you the current state after all events have been processed, so if a key or button has been pressed and released before you process events, then the pressed state will never show up in the

**SDL\_GetKeyboardState** () calls.

Note: This function doesn't take into account whether shift has been pressed or not.

## FUNCTION PARAMETERS

- *numkeys*

  if non-NULL, receives the length of the returned array.

## RETURN VALUE

Returns a pointer to an array of key states.

## THREAD SAFETY

It is safe to call this function from any thread.

## AVAILABILITY

This function is available since SDL 3.2.0.

## SEE ALSO

**•**(3), [**SDL\_PumpEvents**(3)](/SDL_PumpEvents/3.md), **•**(3), [**SDL\_ResetKeyboard**(3)](/SDL_ResetKeyboard/3.md)
