SDL_GetKeyState(3)
πΈ SDL_GetKeyState(3) πΈ
okay bestie, welcome to the SDL API Reference β this is the page for SDL_GetKeyState, and it's literally your little window into what every key on the keyboard is doing right this second π
β¨ NAME β¨
SDL_GetKeyState β get a snapshot of the current keyboard state πΈβ¨οΈ
π SYNOPSIS π
#include "SDL.h"
Uint8 *SDL_GetKeyState(int *numkeys);
π¦ DESCRIPTION π¦
So basically, this function gets you a snapshot of the current keyboard state. Like, right now, who's pressed, who's not. The current state comes back as a pointer to an array, and the size of that array gets stored in numkeys. Yes queen, she tells you how big it is π«Ά
That array is indexed by the SDLK_* symbols β so you go in by key symbol, you come out with the tea.
A value of 1 means the key is pressed. A value of 0 means it's not. That's it. Binary. Iconic.
And listen β the pointer you get back is a pointer to an internal SDL array, so do NOT free it yourself. It's not yours, bestie. She's just letting you look π
Note: use SDL_PumpEvents to update the state array. Otherwise you're looking at stale keyboard lore, no cap.
π EXAMPLE π
Uint8 *keystate = SDL_GetKeyState(NULL);
if ( keystate[SDLK_RETURN] ) printf("Return Key Pressed.
");
π SEE ALSO π
- SDL Key Symbols
SDL_PumpEvents
and that's the whole page, periodt β¨ this one's from the SDL manual, dated Tue 11 Sep 2001, 22:59 β yeah she's vintage but she still ate π π§ββοΈ go press some keys, you got this π
π¦ where this page comes from
- debian bookworm: libsdl1.2-dev 1.2.15+dfsg2-8 Β· LGPL-2.1-or-later
- nixos 26.05: SDL_sixel 0-unstable-2016-02-06
- nixpkgs unstable: SDL_sixel 0-unstable-2016-02-06
- ubuntu jammy: libsdl1.2-dev 1.2.15+dfsg2-6 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms