SDL_GetJoystickHat(3)

πŸ’– SDL_GetJoystickHat(3) πŸ’–

okay bestie so this is a page from the SDL3 FUNCTIONS manual, and today we're learning about POV hats. yes it's a real name, no I will not elaborate. let's get into it πŸŽ€


✨ NAME ✨

SDL_GetJoystickHat</purpose> β€” get the current state of a POV hat on a joystick.

like, the little d-pad-ish thingy. you know the one. πŸ‘‘


✨ SYNOPSIS ✨

#include <SDL3/SDL_joystick.h>

Uint8 SDL_GetJoystickHat(SDL_Joystick *joystick, int hat);

#define SDL_HAT_CENTERED    0x00u
#define SDL_HAT_UP          0x01u
#define SDL_HAT_RIGHT       0x02u
#define SDL_HAT_DOWN        0x04u
#define SDL_HAT_LEFT        0x08u
#define SDL_HAT_RIGHTUP     (SDL_HAT_RIGHT|SDL_HAT_UP)
#define SDL_HAT_RIGHTDOWN   (SDL_HAT_RIGHT|SDL_HAT_DOWN)
#define SDL_HAT_LEFTUP      (SDL_HAT_LEFT|SDL_HAT_UP)
#define SDL_HAT_LEFTDOWN    (SDL_HAT_LEFT|SDL_HAT_DOWN)

look at those SDL_HAT_* constants, they're giving bitmask royalty πŸ’… and yes they combine with | like the little lego bricks they are.


✨ DESCRIPTION ✨

so what you get back is gonna be one of the SDL_HAT_* values. that's it. that's the whole vibe. the returned value will be one of the SDL_HAT_* values. periodt ✨


✨ FUNCTION PARAMETERS ✨

  • joystick β€” an SDL_Joystick structure containing joystick information. your lil joystick info container, your main character 🫢
  • hat β€” the hat index to get the state from; indices start at index 0. yes bestie, zero-indexed, as all things should be.

✨ RETURN VALUE ✨

returns the current hat position. that's the tea. πŸ’–


✨ THREAD SAFETY ✨

it is safe to call this function from any thread. no cap. go wild, thread it from wherever, it's not gonna be dramatic about it 🌈


✨ AVAILABILITY ✨

this function is available since SDL 3.2.0. so if you're on something older… babe. upgrade. 😭


✨ SEE ALSO ✨


and that's the whole page!! mwah πŸ’‹ written by the lovely humans at <b>Simple Directmedia Layer</b>, version <b>SDL 3.4.18</b>, and this iconic lil doc is dated right along with it. slay, go read your hats. πŸ‘‘βœ¨

πŸ“¦ where this page comes from