SDL_AttachVirtualJoystick(3)

πŸ’– SDL_AttachVirtualJoystick(3) πŸ’–

okay bestie, so this is a page from the SDL3 FUNCTIONS manual, and we're about to make a joystick that... doesn't exist. spiritually. let's get into it ✨


✨ NAME ✨

SDL_AttachVirtualJoystick β€” attach a new virtual joystick, no hardware required, it's giving imaginary bestie πŸŽ€


🌈 SYNOPSIS 🌈

#include <SDL3/SDL_joystick.h>

SDL_JoystickID SDL_AttachVirtualJoystick(const SDL_VirtualJoystickDesc *desc);

πŸ’… DESCRIPTION πŸ’…

So here's the tea: apps can literally create virtual joysticks. Like, joysticks that exist with zero hardware backing them up, and all their inputs are supplied by the program. no cap. Once it's attached, a virtual joystick looks exactly like any other joystick SDL can access β€” it's just out there living its life, main character energy, indistinguishable from the real thing. πŸ‘‘

Why would you even do this? Obsessed of you to ask. You can use these to make other things look like joysticks, or to feed in pre-recorded input, etc. it's a whole vibe.

Once it's attached, your app can send joystick inputs to the new virtual joystick using SDL_SetJoystickVirtualAxis(), etc. slay.

And when you're done with it, when it's no longer needed, you can remove the virtual joystick by calling SDL_DetachVirtualJoystick(). closure, healthy, we love to see it πŸ¦‹


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • desc β€” the joystick description, initialized using SDL_INIT_INTERFACE(). don't skip this step bestie, it's literally required. πŸ™ˆ

⭐ RETURN VALUE ⭐

Returns the joystick instance ID πŸ’– β€” or 0 on failure. and if it fails? call SDL_GetError() for more information, she'll tell you what went wrong, no gatekeeping.


πŸ”₯ THREAD SAFETY πŸ”₯

It is safe to call this function from any thread. periodt. call it from wherever, whenever, she's unbothered πŸ’…


🌸 AVAILABILITY 🌸

This function is available since SDL 3.2.0. so if you're on anything older... iykyk, time to update bestie 🧚


πŸ’œ SEE ALSO πŸ’œ

go read those next, they're the rest of the friend group 🫢


ok that's the whole page, you ate that. now go attach a joystick that isn't real. iconic behaviour, honestly. πŸ‘‘

mwah πŸ’‹ β€” brought to you by <strong>Simple Directmedia Layer</strong>, version <strong>SDL 3.4.18</strong>, and this little page is <strong>SDL_AttachVirtualJoystick(3)</strong>. bye bestie, see you in the next manpage πŸ“

πŸ“¦ where this page comes from