SDL_GetKeyboards(3)

πŸ’– SDL_GetKeyboards(3) πŸ’–

okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual, where we're about to find out exactly which keyboards are vibing with your app rn 🎹✨


✨ NAME ✨

SDL_GetKeyboards β€” get a list of currently connected keyboards πŸ’…


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_keyboard.h>

SDL_KeyboardID * SDL_GetKeyboards(int *count);

like. that's it. that's the whole thing. one function call and you get the whole keyboard roster πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so heads up, bestie, because this is the part where it gets a lil unhinged: this list will include any device or virtual driver that includes keyboard functionality. and I do mean any. we're talking some mice 🐭, KVM switches, motherboard power buttons, the whole chaotic ensemble. if it can theoretically squirt out a keystroke, it's showing up here. periodt.

so like… don't just assume a thing is "actively in use" the second you see it in the list. the correct move is to wait for actual input from a device before you count it as actively in use. vibe check first, assumptions never πŸ™ˆ


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • count β€” a pointer that gets filled in with the number of keyboards returned. and guess what? it may be NULL. so if you don't care about the count, you can just pass NULL and move on with your life. iconic behavior honestly.

πŸ’œ RETURN VALUE πŸ’œ

Returns a 0 terminated array of keyboards instance IDs, or NULL on failure 😭 (in which case, call SDL_GetError() for more info, she'll tell you what went wrong).

⚠️ and listen, this array? you gotta free it with SDL_free() when you're done with it. no leaving it lying around, bestie. that's not the vibe.

πŸ”₯ THREAD SAFETY πŸ”₯

this function should only be called on the main thread. main character energy only, no side-quest threads allowed πŸ’€


🌈 AVAILABILITY 🌈

this function has been available since SDL 3.2.0 🫢


πŸ‘‘ SEE ALSO πŸ‘‘


and that's the tea πŸ“ β€” brought to you by Simple Directmedia Layer, SDL 3.4.18, the absolute icon herself. mwah, go forth and enumerate those keyboards πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from