SDL_GamepadDeviceEvent(3type)
๐ SDL_GamepadDeviceEvent โ bestie edition (SDL3 DATATYPES)
okay so you opened the SDL3 DATATYPES section of the manual, and you landed on SDL_GamepadDeviceEvent โ the Gamepad device event structure. yes it's literally the one under event.gdevice.* ๐
โจ NAME โจ
SDL_GamepadDeviceEvent โ the Gamepad device event structure, aka event.gdevice.* ๐ฎ
๐ธ SYNOPSIS ๐ธ
#include <SDL3/SDL_events.h>
typedef struct SDL_GamepadDeviceEvent
{
SDL_EventType type; /**< SDL_EVENT_GAMEPAD_ADDED, SDL_EVENT_GAMEPAD_REMOVED, or SDL_EVENT_GAMEPAD_REMAPPED, SDL_EVENT_GAMEPAD_UPDATE_COMPLETE or SDL_EVENT_GAMEPAD_STEAM_HANDLE_UPDATED */
Uint32 reserved;
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
SDL_JoystickID which; /**< The joystick instance id */
} SDL_GamepadDeviceEvent;
like. look at her. four little fields and she's carrying the whole gamepad-hotplug experience on her back ๐ซถ
Let's go field by field, no skips:
typeโ anSDL_EventType, and it's gonna be one ofSDL_EVENT_GAMEPAD_ADDED,SDL_EVENT_GAMEPAD_REMOVED,SDL_EVENT_GAMEPAD_REMAPPED,SDL_EVENT_GAMEPAD_UPDATE_COMPLETE, orSDL_EVENT_GAMEPAD_STEAM_HANDLE_UPDATED. pick your fighter โจreservedโ aUint32just sitting there. not your business. leave her alone ๐timestampโ aUint64, measured in nanoseconds, and it gets populated usingSDL_GetTicksNS(). so it's giving very precise โฑ๏ธwhichโ anSDL_JoystickID, and it's the joystick instance id. that's the one you actually use to know WHICH gamepad we're talking about ๐
๐ DESCRIPTION ๐
so here's the tea: joysticks that are supported gamepads get both an SDL_JoyDeviceEvent and an SDL_GamepadDeviceEvent. two events, one controller, iconic behaviour honestly ๐
and SDL is not gonna make you wait around for a hotplug moment either. SDL will send GAMEPAD_ADDED events for joysticks that are already plugged in during SDL_Init() and are recognized as gamepads. so yes, your controller that was chilling in the USB port the whole time still gets announced. main character entrance ๐
on top of that, SDL will also send events for joysticks that get gamepad mappings at runtime. so a controller can become a gamepad mid-session and SDL is like "noted, slay" ๐ฅ
๐ฆ AVAILABILITY ๐ฆ
this struct is available since SDL 3.2.0. periodt.
๐ SEE ALSO ๐
SDL_JoyDeviceEvent(3type)โ go read her too, they're a matched set ๐ซถ
and that's the whole vibe check, bestie ๐ that footer energy โ Simple Directmedia Layer, SDL 3.4.18, dated SDL_GamepadDeviceEvent(3type) โ mwah, go plug something in and watch the events roll in ๐ญโจ
๐ฆ 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