SDL_JoyHatEvent(3type)

✨ SDL_JoyHatEvent ✨

okay bestie so you're in the SDL3 DATATYPES section of the manual and you clicked on SDL_JoyHatEvent β€” that's the joystick hat position change event structure, and you'll also catch it lurking as event.jhat.*. πŸ’–


🌸 NAME 🌸

SDL_JoyHatEvent β€” joystick hat position change event structure (event.jhat.*)


πŸŽ€ SYNOPSIS πŸŽ€

#include <SDL3/SDL_events.h>

typedef struct SDL_JoyHatEvent
{
    SDL_EventType type; /**< SDL_EVENT_JOYSTICK_HAT_MOTION */
    Uint32 reserved;
    Uint64 timestamp;   /**< In nanoseconds, populated using SDL_GetTicksNS() */
    SDL_JoystickID which; /**< The joystick instance id */
    Uint8 hat;          /**< The joystick hat index */
    Uint8 value;        /**< The hat position value.
                         *   \sa SDL_HAT_LEFTUP SDL_HAT_UP SDL_HAT_RIGHTUP
                         *   \sa SDL_HAT_LEFT SDL_HAT_CENTERED SDL_HAT_RIGHT
                         *   \sa SDL_HAT_LEFTDOWN SDL_HAT_DOWN SDL_HAT_RIGHTDOWN
                         *
                         *   Note that zero means the POV is centered.
                         */
    Uint8 padding1;
    Uint8 padding2;
} SDL_JoyHatEvent;

πŸ¦‹ DESCRIPTION πŸ¦‹

So like, this struct is what slides into your event queue when somebody yanks a joystick hat around β€” the lil' POV switch on top of a flight stick, yk? it's giving "the hat moved" and nothing else. πŸ‘‘

Here's the cast of characters, field by field:

  • SDL_EventType type β€” bestie this one is literally SDL_EVENT_JOYSTICK_HAT_MOTION, no cap. That's the vibe check that tells you which event you're holding. ✨
  • Uint32 reserved β€” reserved, mind your business, don't touch it. πŸ’…
  • Uint64 timestamp β€” in nanoseconds, populated using SDL_GetTicksNS(). so when did it happen? this. this is when. ⏱️
  • SDL_JoystickID which β€” the joystick instance id. which joystick said that? this is which. iconic honestly. πŸŽ€
  • Uint8 hat β€” the joystick hat index. (yes there can be several hats. a whole hat collection. slay. 🧚)
  • Uint8 value β€” the hat position value. and here's the tea, it cross-references a bunch of constants:
    • SDL_HAT_LEFTUP, SDL_HAT_UP, SDL_HAT_RIGHTUP
    • SDL_HAT_LEFT, SDL_HAT_CENTERED, SDL_HAT_RIGHT
    • SDL_HAT_LEFTDOWN, SDL_HAT_DOWN, SDL_HAT_RIGHTDOWN
⚠️ and note, bestie: zero means the POV is centered. that's the important one, don't forget it. 😭
  • Uint8 padding1 β€” padding. structural. not for you. πŸ™ˆ
  • Uint8 padding2 β€” also padding. also not for you. πŸ™ˆ

πŸ’« AVAILABILITY πŸ’«

This struct is available since SDL 3.2.0. so if you're on something older, it's not gonna be there, fr fr. πŸ’€


and that's the whole page, bestie β€” you ate that, honestly. 🌈

this lil' writeup is part of Simple Directmedia Layer, SDL 3.4.18, and it lives in the manual as SDL_JoyHatEvent(3type). go forth and read your hat events πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from