SDL_GetKeyboardState(3)
π SDL_GetKeyboardState π
okay bestie, so this is a page from the SDL3 FUNCTIONS manual, and it's genuinely one of the most useful little gremlins in the whole keyboard family. let's get into it π
β¨ NAME β¨
SDL_GetKeyboardState β grab a snapshot of the current state of the keyboard πΈβ¨οΈ
β¨ SYNOPSIS β¨
#include <SDL3/SDL_keyboard.h>
const bool * SDL_GetKeyboardState(int *numkeys);
β¨ DESCRIPTION β¨
so the pointer you get back? it's a pointer to an internal SDL array. like, SDL's own array. it stays valid for the whole lifetime of the application, and you should not free it yourself β not your array, not your problem, hands off π
if an element in that array is true, that key is pressed. if it's false, it is not. periodt. and the way you index into it is by using SDL_Scancode values. iykyk π
want the state array to actually update? call SDL_PumpEvents(). that's the vibe check that refreshes everything π«Ά
this function hands you the current state after all events have been processed. which means β and this is the important part, don't skip it β if a key or button got pressed and released before you ever processed events, then that pressed state will never show up in your SDL_GetKeyboardState() calls. it's gone. poof. not coming back π
Note: this function doesn't take into account whether shift has been pressed or not. like, shift is simply not part of the conversation here π
β¨ FUNCTION PARAMETERS β¨
numkeysβ if it's non-NULL, it receives the length of the returned array. if it'sNULL, she just doesn't tell you the length, no biggie πΈ
β¨ RETURN VALUE β¨
Returns a pointer to an array of key states. that's the whole gift π
β¨ THREAD SAFETY β¨
it is safe to call this function from any thread. yes bestie, any. go off π
β¨ AVAILABILITY β¨
this function is available since SDL 3.2.0 β
β¨ SEE ALSO β¨
Simple Directmedia Layer β’ SDL 3.4.18 β’ SDL_GetKeyboardState(3)
and that's the whole page, bestie π¦ mwah, go press some keys β this doc is from Simple Directmedia Layer, SDL 3.4.18, and it's literally titled SDL_GetKeyboardState(3). slay πβ¨
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms