SDL_GetGamepads(3)

๐Ÿ’– SDL_GetGamepads ๐Ÿ’–

okay bestie, welcome to the SDL3 FUNCTIONS corner of the man pages, this one's SDL_GetGamepads(3) and she's literally so useful ๐ŸŽฎโœจ


๐ŸŒธ NAME ๐ŸŒธ

SDL_GetGamepads โ€” get a list of currently connected gamepads.

like, all of them. every single controller plugged in / paired / vibing nearby. it's giving census day for gamepads ๐Ÿซถ


โœจ SYNOPSIS โœจ

#include <SDL3/SDL_gamepad.h>

SDL_JoystickID * SDL_GetGamepads(int *count);

๐ŸŽ€ FUNCTION PARAMETERS ๐ŸŽ€

  • count โ€” a pointer that gets filled in with the number of gamepads returned. it may be NULL if you truly don't care how many there are, no pressure bestie ๐Ÿ’…

๐Ÿฆ‹ RETURN VALUE ๐Ÿฆ‹

returns a 0 terminated array of joystick instance IDs, or NULL on failure. if it's NULL, go call SDL_GetError() for the tea โ˜• โ€” she'll tell you what went wrong.

important!! when you're done with that array, free it with SDL_free(). don't just leave it hanging, that's not the vibe, that's a leak ๐Ÿ˜ญ

๐ŸŒˆ THREAD SAFETY ๐ŸŒˆ

it is safe to call this function from any thread. yes, any. go wild, main character energy, no locks required ๐Ÿ”ฅ


โญ AVAILABILITY โญ

this function is available since SDL 3.2.0. if you're on something older, she simply doesn't exist yet, sorry babe ๐Ÿ’€


๐Ÿ‘‘ SEE ALSO ๐Ÿ‘‘


and that's the whole page, bestie, you ate that ๐Ÿ“

signing off with the receipts: this one comes from Simple Directmedia Layer, version SDL 3.4.18, and it's the SDL_GetGamepads(3) page. go forth and enumerate those controllers ๐Ÿ’œ๐Ÿงš

๐Ÿ“ฆ where this page comes from