joystick topic
CategoryJoystick
SDL joystick support.
This is the lower-level joystick handling. If you want the simpler option, where what each button does is well-defined, you should use the gamepad API instead.
The term "instance_id" is the current instantiation of a joystick device in the system. If the joystick is removed and then re-inserted then it will get a new instance_id. instance_id's are monotonically increasing identifiers of a joystick plugged in.
The term "player_index" is the number assigned to a player on a specific controller. For XInput controllers this returns the XInput user index. Many joysticks will not be able to supply this information.
SDL_GUID is used as a stable 128-bit identifier for a joystick device that does not change over time. It identifies class of the device (a X360 wired controller for example). This identifier is platform dependent.
In order to use these functions, SDL_Init() must have been called with the SDL_INIT_JOYSTICK flag. This causes SDL to scan the system for joysticks, and load appropriate drivers.
If you would like to receive joystick updates while the application is in the background, you should set the following hint before calling SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
SDL can provide virtual joysticks as well: the app defines an imaginary controller with SDL_AttachVirtualJoystick(), and then can provide inputs for it via SDL_SetJoystickVirtualAxis(), SDL_SetJoystickVirtualButton(), etc. As this data is supplied, it will look like a normal joystick to SDL, just not backed by a hardware driver. This has been used to make unusual devices, like VR headset controllers, look like normal joysticks, or provide recording/playback of game inputs, etc.
Classes
Functions
-
sdlAttachVirtualJoystick(
Pointer< joystickSdlVirtualJoystickDesc> desc) → int - Attach a new virtual joystick.
-
sdlCloseJoystick(
Pointer< joystickSdlJoystick> joystick) → void - Close a joystick previously opened with SDL_OpenJoystick().
-
sdlDetachVirtualJoystick(
int instanceId) → bool joystick - Detach a virtual joystick.
-
sdlGetJoystickAxis(
Pointer< joystickSdlJoystick> joystick, int axis) → int - Get the current state of an axis control on a joystick.
-
sdlGetJoystickAxisInitialState(
Pointer< joystickSdlJoystick> joystick, int axis, Pointer<Int16> state) → bool - Get the initial state of an axis control on a joystick.
-
sdlGetJoystickBall(
Pointer< joystickSdlJoystick> joystick, int ball, Pointer<Int32> dx, Pointer<Int32> dy) → bool - Get the ball axis change since the last poll.
-
sdlGetJoystickButton(
Pointer< joystickSdlJoystick> joystick, int button) → bool - Get the current state of a button on a joystick.
-
sdlGetJoystickConnectionState(
Pointer< joystickSdlJoystick> joystick) → int - Get the connection state of a joystick.
-
sdlGetJoystickFirmwareVersion(
Pointer< joystickSdlJoystick> joystick) → int - Get the firmware version of an opened joystick, if available.
-
sdlGetJoystickFromId(
int instanceId) → Pointer< joystickSdlJoystick> - Get the SDL_Joystick associated with an instance ID, if it has been opened.
-
sdlGetJoystickFromPlayerIndex(
int playerIndex) → Pointer< joystickSdlJoystick> - Get the SDL_Joystick associated with a player index.
-
sdlGetJoystickGuid(
Pointer< joystickSdlJoystick> joystick) → SdlGuid - Get the implementation-dependent GUID for the joystick.
-
sdlGetJoystickGuidForId(
int instanceId) → SdlGuid joystick - Get the implementation-dependent GUID of a joystick.
-
sdlGetJoystickGuidInfo(
SdlGuid guid, Pointer< joystickUint16> vendor, Pointer<Uint16> product, Pointer<Uint16> version, Pointer<Uint16> crc16) → void - Get the device information encoded in a SDL_GUID structure.
-
sdlGetJoystickHat(
Pointer< joystickSdlJoystick> joystick, int hat) → int - Get the current state of a POV hat on a joystick.
-
sdlGetJoystickId(
Pointer< joystickSdlJoystick> joystick) → int - Get the instance ID of an opened joystick.
-
sdlGetJoystickName(
Pointer< joystickSdlJoystick> joystick) → String? - Get the implementation dependent name of a joystick.
-
sdlGetJoystickNameForId(
int instanceId) → String? joystick - Get the implementation dependent name of a joystick.
-
sdlGetJoystickPath(
Pointer< joystickSdlJoystick> joystick) → String? - Get the implementation dependent path of a joystick.
-
sdlGetJoystickPathForId(
int instanceId) → String? joystick - Get the implementation dependent path of a joystick.
-
sdlGetJoystickPlayerIndex(
Pointer< joystickSdlJoystick> joystick) → int - Get the player index of an opened joystick.
-
sdlGetJoystickPlayerIndexForId(
int instanceId) → int joystick - Get the player index of a joystick.
-
sdlGetJoystickPowerInfo(
Pointer< joystickSdlJoystick> joystick, Pointer<Int32> percent) → int - Get the battery state of a joystick.
-
sdlGetJoystickProduct(
Pointer< joystickSdlJoystick> joystick) → int - Get the USB product ID of an opened joystick, if available.
-
sdlGetJoystickProductForId(
int instanceId) → int joystick - Get the USB product ID of a joystick, if available.
-
sdlGetJoystickProductVersion(
Pointer< joystickSdlJoystick> joystick) → int - Get the product version of an opened joystick, if available.
-
sdlGetJoystickProductVersionForId(
int instanceId) → int joystick - Get the product version of a joystick, if available.
-
sdlGetJoystickProperties(
Pointer< joystickSdlJoystick> joystick) → int - Get the properties associated with a joystick.
-
sdlGetJoysticks(
Pointer< joystickInt32> count) → Pointer<Uint32> - Get a list of currently connected joysticks.
-
sdlGetJoystickSerial(
Pointer< joystickSdlJoystick> joystick) → String? - Get the serial number of an opened joystick, if available.
-
sdlGetJoystickType(
Pointer< joystickSdlJoystick> joystick) → int - Get the type of an opened joystick.
-
sdlGetJoystickTypeForId(
int instanceId) → int joystick - Get the type of a joystick, if available.
-
sdlGetJoystickVendor(
Pointer< joystickSdlJoystick> joystick) → int - Get the USB vendor ID of an opened joystick, if available.
-
sdlGetJoystickVendorForId(
int instanceId) → int joystick - Get the USB vendor ID of a joystick, if available.
-
sdlGetNumJoystickAxes(
Pointer< joystickSdlJoystick> joystick) → int - Get the number of general axis controls on a joystick.
-
sdlGetNumJoystickBalls(
Pointer< joystickSdlJoystick> joystick) → int - Get the number of trackballs on a joystick.
-
sdlGetNumJoystickButtons(
Pointer< joystickSdlJoystick> joystick) → int - Get the number of buttons on a joystick.
-
sdlGetNumJoystickHats(
Pointer< joystickSdlJoystick> joystick) → int - Get the number of POV hats on a joystick.
-
sdlHasJoystick(
) → bool joystick - Return whether a joystick is currently connected.
-
sdlIsJoystickVirtual(
int instanceId) → bool joystick - Query whether or not a joystick is virtual.
-
sdlJoystickConnected(
Pointer< joystickSdlJoystick> joystick) → bool - Get the status of a specified joystick.
-
sdlJoystickEventsEnabled(
) → bool joystick - Query the state of joystick event processing.
-
sdlLockJoysticks(
Pointer< joystickNativeType> arg0) → void - Locking for atomic access to the joystick API.
-
sdlOpenJoystick(
int instanceId) → Pointer< joystickSdlJoystick> - Open a joystick for use.
-
sdlRumbleJoystick(
Pointer< joystickSdlJoystick> joystick, int lowFrequencyRumble, int highFrequencyRumble, int durationMs) → bool - Start a rumble effect.
-
sdlRumbleJoystickTriggers(
Pointer< joystickSdlJoystick> joystick, int leftRumble, int rightRumble, int durationMs) → bool - Start a rumble effect in the joystick's triggers.
-
sdlSendJoystickEffect(
Pointer< joystickSdlJoystick> joystick, Pointer<NativeType> data, int size) → bool - Send a joystick specific effect packet.
-
sdlSendJoystickVirtualSensorData(
Pointer< joystickSdlJoystick> joystick, int type, int sensorTimestamp, Pointer<Float> data, int numValues) → bool - Send a sensor update for an opened virtual joystick.
-
sdlSetJoystickEventsEnabled(
bool enabled) → void joystick - Set the state of joystick event processing.
-
sdlSetJoystickLed(
Pointer< joystickSdlJoystick> joystick, int red, int green, int blue) → bool - Update a joystick's LED color.
-
sdlSetJoystickPlayerIndex(
Pointer< joystickSdlJoystick> joystick, int playerIndex) → bool - Set the player index of an opened joystick.
-
sdlSetJoystickVirtualAxis(
Pointer< joystickSdlJoystick> joystick, int axis, int value) → bool - Set the state of an axis on an opened virtual joystick.
-
sdlSetJoystickVirtualBall(
Pointer< joystickSdlJoystick> joystick, int ball, int xrel, int yrel) → bool - Generate ball motion on an opened virtual joystick.
-
sdlSetJoystickVirtualButton(
Pointer< joystickSdlJoystick> joystick, int button, bool down) → bool - Set the state of a button on an opened virtual joystick.
-
sdlSetJoystickVirtualHat(
Pointer< joystickSdlJoystick> joystick, int hat, int value) → bool - Set the state of a hat on an opened virtual joystick.
-
sdlSetJoystickVirtualTouchpad(
Pointer< joystickSdlJoystick> joystick, int touchpad, int finger, bool down, double x, double y, double pressure) → bool - Set touchpad finger state on an opened virtual joystick.
-
sdlUnlockJoysticks(
Pointer< joystickNativeType> arg0) → void - Unlocking for atomic access to the joystick API.
-
sdlUpdateJoysticks(
) → void joystick - Update the current state of the open joysticks.