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