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 โ€” an SDL_EventType, and it's gonna be one of SDL_EVENT_GAMEPAD_ADDED, SDL_EVENT_GAMEPAD_REMOVED, SDL_EVENT_GAMEPAD_REMAPPED, SDL_EVENT_GAMEPAD_UPDATE_COMPLETE, or SDL_EVENT_GAMEPAD_STEAM_HANDLE_UPDATED. pick your fighter โœจ
  • reserved โ€” a Uint32 just sitting there. not your business. leave her alone ๐Ÿ™ˆ
  • timestamp โ€” a Uint64, measured in nanoseconds, and it gets populated using SDL_GetTicksNS(). so it's giving very precise โฑ๏ธ
  • which โ€” an SDL_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 ๐ŸŒˆ


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