SDL_SetJoystickVirtualButton(3)
๐ SDL_SetJoystickVirtualButton(3) ๐
okay bestie, welcome to the SDL3 FUNCTIONS section of the manual, and lemme tell you, this one is a whole vibe. it's all about poking the buttons on a virtual joystick you made yourself. iconic behavior honestly ๐ฎโจ
โจ NAME โจ
SDL_SetJoystickVirtualButton โ set the state of a button on an opened virtual joystick, fr fr.
๐ธ SYNOPSIS ๐ธ
#include <SDL3/SDL_joystick.h>
bool SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, bool down);
๐ฆ DESCRIPTION ๐ฆ
so like, this function lets you flip a button on a virtual joystick โ pressed or not pressed, your call, no cap.
but IMPORTANT, and I cannot stress this enough: the values you set here are not applied until the next call to SDL_UpdateJoysticks. not immediately. not right this second. the next one. ๐ซ
and SDL_UpdateJoysticks can be called directly, or it can sneak in indirectly through a bunch of other SDL APIs, including but not limited to:
SDL_PollEventSDL_PumpEventsSDL_WaitEventTimeoutSDL_WaitEvent
so basically you set it, and then something updates it eventually, and that's when the world finds out ๐
๐ FUNCTION PARAMETERS ๐
joystickโ the virtual joystick on which to set state. this is your joystick, the one you're setting state on, periodt.buttonโ the index of the button on the virtual joystick to update. yes, an index, not a name, not a vibe, a number.downโtrueif the button is pressed,falseotherwise. that's it, that's the whole boolean, she's simple and she's slaying ๐
โญ RETURN VALUE โญ
returns true on success or false on failure. and if it fails? call SDL_GetError() for more information, she'll tell you what went wrong ๐ฅบ
๐ง THREAD SAFETY ๐ง
it is safe to call this function from any thread. any thread. all the threads. every thread. go off, multitasking queen ๐
๐ AVAILABILITY ๐
this function is available since SDL 3.2.0. so if you're on something older, sorry bestie, no button-setting for you ๐
๐ SEE ALSO ๐
SDL_SetJoystickVirtualAxis(3)SDL_SetJoystickVirtualBall(3)SDL_SetJoystickVirtualHat(3)SDL_SetJoystickVirtualTouchpad(3)SDL_SetJoystickVirtualSensorData(3)
and that's the whole page babes ๐ซถ this little love letter to virtual joystick buttons comes to you courtesy of Simple Directmedia Layer, version SDL 3.4.18, and yes she ate and left no crumbs. mwah ๐
๐ฆ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 ยท Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 ยท Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 ยท Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 ยท Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms