sdlxAttachVirtualJoystick function joystick

int sdlxAttachVirtualJoystick(
  1. SdlxVirtualJoystickDesc desc
)

Attach a new virtual joystick.

Apps can create virtual joysticks, that exist without hardware directly backing them, and have program-supplied inputs. Once attached, a virtual joystick looks like any other joystick that SDL can access. These can be used to make other things look like joysticks, or provide pre-recorded input, etc.

Once attached, the app can send joystick inputs to the new virtual joystick using SDL_SetJoystickVirtualAxis(), etc.

When no longer needed, the virtual joystick can be removed by calling SDL_DetachVirtualJoystick().

\param desc joystick description, initialized using SDL_INIT_INTERFACE(). \returns the joystick instance ID, or 0 on failure; call SDL_GetError() for more information.

\threadsafety It is safe to call this function from any thread.

\since This function is available since SDL 3.2.0.

\sa SDL_DetachVirtualJoystick \sa SDL_SetJoystickVirtualAxis \sa SDL_SetJoystickVirtualButton \sa SDL_SetJoystickVirtualBall \sa SDL_SetJoystickVirtualHat \sa SDL_SetJoystickVirtualTouchpad \sa SDL_SetJoystickVirtualSensorData

extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_AttachVirtualJoystick(const SDL_VirtualJoystickDesc *desc)

Implementation

int sdlxAttachVirtualJoystick(SdlxVirtualJoystickDesc desc) {
  final descPointer = desc.calloc();
  final result = sdlAttachVirtualJoystick(descPointer);
  descPointer.callocAllFree();
  return result;
}