SDL_SetJoystickVirtualHat(3)

โœจ SDL_SetJoystickVirtualHat โœจ

okay so bestie, welcome to the SDL3 FUNCTIONS manual, and today's main character is SDL_SetJoystickVirtualHat(3) ๐Ÿ’… she sets the state of a hat on an opened virtual joystick, and honestly? she eats.


๐ŸŽ€ NAME ๐ŸŽ€

SDL_SetJoystickVirtualHat โ€” set the state of a hat on an opened virtual joystick. no cap, that's literally the whole job description ๐Ÿซถ


๐ŸŒธ SYNOPSIS ๐ŸŒธ

#include <SDL3/SDL_joystick.h>

bool SDL_SetJoystickVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value);

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

okay so here's the tea, and it's important tea โ˜• โ€” the values you set here do NOT get applied right away. they're just vibing in limbo until the next call to SDL_UpdateJoysticks. and that call can happen either:

  • directly, by you calling it yourself, or
  • indirectly, through various other SDL APIs, including โ€” but not limited to โ€” SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout, and SDL_WaitEvent.

so like. it's giving "queued up, pending, waiting for her moment" ๐Ÿ’… the hat state is not real until the update happens. periodt.


๐Ÿ’– FUNCTION PARAMETERS ๐Ÿ’–

  • joystick โ€” the virtual joystick on which to set state. your girl. the one you're messing with ๐ŸŽฎ
  • hat โ€” the index of the hat on the virtual joystick to update. yes, an index, so you gotta know which hat you mean ๐Ÿ‘‘
  • value โ€” the new value for the specified hat. the fresh fit you're dressing it in โœจ

๐ŸŒˆ RETURN VALUE ๐ŸŒˆ

returns true on success, or false on failure ๐Ÿ˜ญ and if it fails, hit up SDL_GetError() for more information โ€” she will tell you what went wrong, fr fr.


๐Ÿ”ฅ THREAD SAFETY ๐Ÿ”ฅ

it is safe to call this function from any thread. multithreaded besties, you are SO valid ๐Ÿซถ no locks, no drama, no stress.


โญ AVAILABILITY โญ

this function is available since SDL 3.2.0. if you're on anything older, she simply does not exist yet, sorry babe ๐Ÿ™ˆ


๐Ÿ‘‘ SEE ALSO ๐Ÿ‘‘

the whole virtual-joystick friend group, all iconic, all linked:


quick vibe check ๐Ÿ’€ remember: set the hat, then call SDL_UpdateJoysticks (or one of the event functions) or it's giving nothing. the hat does not exist until you do.

and that's a wrap on our girl ๐ŸŒธ this page comes to you from Simple Directmedia Layer, version SDL 3.4.18, and the date stamped on it โ€” mwah, chef's kiss ๐ŸŽ€ go forth, set your hats, and slay ๐Ÿ’…โœจ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from