SDL_GamepadSensorEvent(3type)

๐ŸŽ€ SDL_GamepadSensorEvent โ€” bestie, it's a 3type and it's iconic

okay so first things first: the manual page is called SDL_GamepadSensorEvent(3type), and it lives in the SDL3 DATATYPES section of the manual. yes we're reading a datatype page. yes it's gonna be fun. buckle up ๐Ÿ’–


โœจ NAME โœจ

SDL_GamepadSensorEvent โ€” the Gamepad sensor event structure, aka event.gsensor.*

like. that's the whole vibe. when your gamepad's lil sensors go brrr, this is the struct that shows up to the party ๐ŸŽ‰


๐ŸŒธ SYNOPSIS ๐ŸŒธ

pull it in with:

#include <SDL3/SDL_events.h>

and here's the whole struct, verbatim, no edits, no notes, no cap:

typedef struct SDL_GamepadSensorEvent
{
    SDL_EventType type; /**< SDL_EVENT_GAMEPAD_SENSOR_UPDATE */
    Uint32 reserved;
    Uint64 timestamp;   /**< In nanoseconds, populated using SDL_GetTicksNS() */
    SDL_JoystickID which; /**< The joystick instance id */
    Sint32 sensor;      /**< The type of the sensor, one of the values of SDL_SensorType */
    float data[3];      /**< Up to 3 values from the sensor, as defined in SDL_sensor.h */
    Uint64 sensor_timestamp; /**< The timestamp of the sensor reading in nanoseconds, not necessarily synchronized with the system clock */
} SDL_GamepadSensorEvent;

let's do a lil tour of the members, because every single one of them matters and I am not skipping any ๐Ÿซถ

  • type โ€” it's an SDL_EventType, and it's literally SDL_EVENT_GAMEPAD_SENSOR_UPDATE. that's the whole personality. when you see this type, you know a sensor just spoke up โœจ
  • reserved โ€” a Uint32 sitting there being mysterious. don't touch it, don't ask it questions, it's reserved bestie ๐Ÿ’…
  • timestamp โ€” a Uint64, measured in nanoseconds, populated using SDL_GetTicksNS(). that's your "when did this event happen" clock โฐ
  • which โ€” an SDL_JoystickID, and it's the joystick instance id. which gamepad was it? this one. ๐ŸŽฎ
  • sensor โ€” a Sint32 holding the type of the sensor, and it's one of the values of SDL_SensorType. so like, which sensor is yapping ๐Ÿ“ฃ
  • data[3] โ€” an array of float, up to 3 values from the sensor, as defined in SDL_sensor.h. up to three!! not guaranteed three!! ๐Ÿ‘€
  • sensor_timestamp โ€” a Uint64, the timestamp of the sensor reading in nanoseconds, and > heads up: it is not necessarily synchronized with the system clock. so don't go comparing it to timestamp like they're the same clock, because they might not be, and that's just how it is ๐Ÿ˜ญ

๐ŸŒˆ AVAILABILITY ๐ŸŒˆ

this struct has been available since SDL 3.2.0. so if you're on something older... girl. upgrade. ๐Ÿฆ‹


๐Ÿ’œ one last thing

that's the whole page, no more sections hiding under the bed, promise ๐Ÿงš

and a lil sign-off: this page comes to you from Simple Directmedia Layer, and the version on the tin is SDL 3.4.18. mwah, go read your sensor data responsibly ๐Ÿ‘‘๐Ÿ’–

๐Ÿ“ฆ where this page comes from