Path: blob/master/thirdparty/sdl/include/SDL3/SDL_joystick.h
9912 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/2021/**22* # CategoryJoystick23*24* SDL joystick support.25*26* This is the lower-level joystick handling. If you want the simpler option,27* where what each button does is well-defined, you should use the gamepad API28* instead.29*30* The term "instance_id" is the current instantiation of a joystick device in31* the system, if the joystick is removed and then re-inserted then it will32* get a new instance_id, instance_id's are monotonically increasing33* identifiers of a joystick plugged in.34*35* The term "player_index" is the number assigned to a player on a specific36* controller. For XInput controllers this returns the XInput user index. Many37* joysticks will not be able to supply this information.38*39* SDL_GUID is used as a stable 128-bit identifier for a joystick device that40* does not change over time. It identifies class of the device (a X360 wired41* controller for example). This identifier is platform dependent.42*43* In order to use these functions, SDL_Init() must have been called with the44* SDL_INIT_JOYSTICK flag. This causes SDL to scan the system for joysticks,45* and load appropriate drivers.46*47* If you would like to receive joystick updates while the application is in48* the background, you should set the following hint before calling49* SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS50*/5152#ifndef SDL_joystick_h_53#define SDL_joystick_h_5455#include <SDL3/SDL_stdinc.h>56#include <SDL3/SDL_error.h>57#include <SDL3/SDL_guid.h>58#include <SDL3/SDL_mutex.h>59#include <SDL3/SDL_power.h>60#include <SDL3/SDL_properties.h>61#include <SDL3/SDL_sensor.h>6263#include <SDL3/SDL_begin_code.h>64/* Set up for C function definitions, even when using C++ */65#ifdef __cplusplus66extern "C" {67#endif6869#ifdef SDL_THREAD_SAFETY_ANALYSIS70/*71* This is not an exported symbol from SDL, this is only in the headers to72* help Clang's thread safety analysis tools to function. Do not attempt73* to access this symbol from your app, it will not work!74*/75extern SDL_Mutex *SDL_joystick_lock;76#endif7778/**79* The joystick structure used to identify an SDL joystick.80*81* This is opaque data.82*83* \since This struct is available since SDL 3.2.0.84*/85typedef struct SDL_Joystick SDL_Joystick;8687/**88* This is a unique ID for a joystick for the time it is connected to the89* system, and is never reused for the lifetime of the application.90*91* If the joystick is disconnected and reconnected, it will get a new ID.92*93* The value 0 is an invalid ID.94*95* \since This datatype is available since SDL 3.2.0.96*/97typedef Uint32 SDL_JoystickID;9899/**100* An enum of some common joystick types.101*102* In some cases, SDL can identify a low-level joystick as being a certain103* type of device, and will report it through SDL_GetJoystickType (or104* SDL_GetJoystickTypeForID).105*106* This is by no means a complete list of everything that can be plugged into107* a computer.108*109* \since This enum is available since SDL 3.2.0.110*/111typedef enum SDL_JoystickType112{113SDL_JOYSTICK_TYPE_UNKNOWN,114SDL_JOYSTICK_TYPE_GAMEPAD,115SDL_JOYSTICK_TYPE_WHEEL,116SDL_JOYSTICK_TYPE_ARCADE_STICK,117SDL_JOYSTICK_TYPE_FLIGHT_STICK,118SDL_JOYSTICK_TYPE_DANCE_PAD,119SDL_JOYSTICK_TYPE_GUITAR,120SDL_JOYSTICK_TYPE_DRUM_KIT,121SDL_JOYSTICK_TYPE_ARCADE_PAD,122SDL_JOYSTICK_TYPE_THROTTLE,123SDL_JOYSTICK_TYPE_COUNT124} SDL_JoystickType;125126/**127* Possible connection states for a joystick device.128*129* This is used by SDL_GetJoystickConnectionState to report how a device is130* connected to the system.131*132* \since This enum is available since SDL 3.2.0.133*/134typedef enum SDL_JoystickConnectionState135{136SDL_JOYSTICK_CONNECTION_INVALID = -1,137SDL_JOYSTICK_CONNECTION_UNKNOWN,138SDL_JOYSTICK_CONNECTION_WIRED,139SDL_JOYSTICK_CONNECTION_WIRELESS140} SDL_JoystickConnectionState;141142/**143* The largest value an SDL_Joystick's axis can report.144*145* \since This macro is available since SDL 3.2.0.146*147* \sa SDL_JOYSTICK_AXIS_MIN148*/149#define SDL_JOYSTICK_AXIS_MAX 32767150151/**152* The smallest value an SDL_Joystick's axis can report.153*154* This is a negative number!155*156* \since This macro is available since SDL 3.2.0.157*158* \sa SDL_JOYSTICK_AXIS_MAX159*/160#define SDL_JOYSTICK_AXIS_MIN -32768161162163/* Function prototypes */164165/**166* Locking for atomic access to the joystick API.167*168* The SDL joystick functions are thread-safe, however you can lock the169* joysticks while processing to guarantee that the joystick list won't change170* and joystick and gamepad events will not be delivered.171*172* \since This function is available since SDL 3.2.0.173*/174extern SDL_DECLSPEC void SDLCALL SDL_LockJoysticks(void) SDL_ACQUIRE(SDL_joystick_lock);175176/**177* Unlocking for atomic access to the joystick API.178*179* \since This function is available since SDL 3.2.0.180*/181extern SDL_DECLSPEC void SDLCALL SDL_UnlockJoysticks(void) SDL_RELEASE(SDL_joystick_lock);182183/**184* Return whether a joystick is currently connected.185*186* \returns true if a joystick is connected, false otherwise.187*188* \since This function is available since SDL 3.2.0.189*190* \sa SDL_GetJoysticks191*/192extern SDL_DECLSPEC bool SDLCALL SDL_HasJoystick(void);193194/**195* Get a list of currently connected joysticks.196*197* \param count a pointer filled in with the number of joysticks returned, may198* be NULL.199* \returns a 0 terminated array of joystick instance IDs or NULL on failure;200* call SDL_GetError() for more information. This should be freed201* with SDL_free() when it is no longer needed.202*203* \since This function is available since SDL 3.2.0.204*205* \sa SDL_HasJoystick206* \sa SDL_OpenJoystick207*/208extern SDL_DECLSPEC SDL_JoystickID * SDLCALL SDL_GetJoysticks(int *count);209210/**211* Get the implementation dependent name of a joystick.212*213* This can be called before any joysticks are opened.214*215* \param instance_id the joystick instance ID.216* \returns the name of the selected joystick. If no name can be found, this217* function returns NULL; call SDL_GetError() for more information.218*219* \since This function is available since SDL 3.2.0.220*221* \sa SDL_GetJoystickName222* \sa SDL_GetJoysticks223*/224extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickNameForID(SDL_JoystickID instance_id);225226/**227* Get the implementation dependent path of a joystick.228*229* This can be called before any joysticks are opened.230*231* \param instance_id the joystick instance ID.232* \returns the path of the selected joystick. If no path can be found, this233* function returns NULL; call SDL_GetError() for more information.234*235* \since This function is available since SDL 3.2.0.236*237* \sa SDL_GetJoystickPath238* \sa SDL_GetJoysticks239*/240extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickPathForID(SDL_JoystickID instance_id);241242/**243* Get the player index of a joystick.244*245* This can be called before any joysticks are opened.246*247* \param instance_id the joystick instance ID.248* \returns the player index of a joystick, or -1 if it's not available.249*250* \since This function is available since SDL 3.2.0.251*252* \sa SDL_GetJoystickPlayerIndex253* \sa SDL_GetJoysticks254*/255extern SDL_DECLSPEC int SDLCALL SDL_GetJoystickPlayerIndexForID(SDL_JoystickID instance_id);256257/**258* Get the implementation-dependent GUID of a joystick.259*260* This can be called before any joysticks are opened.261*262* \param instance_id the joystick instance ID.263* \returns the GUID of the selected joystick. If called with an invalid264* instance_id, this function returns a zero GUID.265*266* \since This function is available since SDL 3.2.0.267*268* \sa SDL_GetJoystickGUID269* \sa SDL_GUIDToString270*/271extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GetJoystickGUIDForID(SDL_JoystickID instance_id);272273/**274* Get the USB vendor ID of a joystick, if available.275*276* This can be called before any joysticks are opened. If the vendor ID isn't277* available this function returns 0.278*279* \param instance_id the joystick instance ID.280* \returns the USB vendor ID of the selected joystick. If called with an281* invalid instance_id, this function returns 0.282*283* \since This function is available since SDL 3.2.0.284*285* \sa SDL_GetJoystickVendor286* \sa SDL_GetJoysticks287*/288extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickVendorForID(SDL_JoystickID instance_id);289290/**291* Get the USB product ID of a joystick, if available.292*293* This can be called before any joysticks are opened. If the product ID isn't294* available this function returns 0.295*296* \param instance_id the joystick instance ID.297* \returns the USB product ID of the selected joystick. If called with an298* invalid instance_id, this function returns 0.299*300* \since This function is available since SDL 3.2.0.301*302* \sa SDL_GetJoystickProduct303* \sa SDL_GetJoysticks304*/305extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductForID(SDL_JoystickID instance_id);306307/**308* Get the product version of a joystick, if available.309*310* This can be called before any joysticks are opened. If the product version311* isn't available this function returns 0.312*313* \param instance_id the joystick instance ID.314* \returns the product version of the selected joystick. If called with an315* invalid instance_id, this function returns 0.316*317* \since This function is available since SDL 3.2.0.318*319* \sa SDL_GetJoystickProductVersion320* \sa SDL_GetJoysticks321*/322extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductVersionForID(SDL_JoystickID instance_id);323324/**325* Get the type of a joystick, if available.326*327* This can be called before any joysticks are opened.328*329* \param instance_id the joystick instance ID.330* \returns the SDL_JoystickType of the selected joystick. If called with an331* invalid instance_id, this function returns332* `SDL_JOYSTICK_TYPE_UNKNOWN`.333*334* \since This function is available since SDL 3.2.0.335*336* \sa SDL_GetJoystickType337* \sa SDL_GetJoysticks338*/339extern SDL_DECLSPEC SDL_JoystickType SDLCALL SDL_GetJoystickTypeForID(SDL_JoystickID instance_id);340341/**342* Open a joystick for use.343*344* The joystick subsystem must be initialized before a joystick can be opened345* for use.346*347* \param instance_id the joystick instance ID.348* \returns a joystick identifier or NULL on failure; call SDL_GetError() for349* more information.350*351* \since This function is available since SDL 3.2.0.352*353* \sa SDL_CloseJoystick354*/355extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_OpenJoystick(SDL_JoystickID instance_id);356357/**358* Get the SDL_Joystick associated with an instance ID, if it has been opened.359*360* \param instance_id the instance ID to get the SDL_Joystick for.361* \returns an SDL_Joystick on success or NULL on failure or if it hasn't been362* opened yet; call SDL_GetError() for more information.363*364* \since This function is available since SDL 3.2.0.365*/366extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetJoystickFromID(SDL_JoystickID instance_id);367368/**369* Get the SDL_Joystick associated with a player index.370*371* \param player_index the player index to get the SDL_Joystick for.372* \returns an SDL_Joystick on success or NULL on failure; call SDL_GetError()373* for more information.374*375* \since This function is available since SDL 3.2.0.376*377* \sa SDL_GetJoystickPlayerIndex378* \sa SDL_SetJoystickPlayerIndex379*/380extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetJoystickFromPlayerIndex(int player_index);381382/**383* The structure that describes a virtual joystick touchpad.384*385* \since This struct is available since SDL 3.2.0.386*387* \sa SDL_VirtualJoystickDesc388*/389typedef struct SDL_VirtualJoystickTouchpadDesc390{391Uint16 nfingers; /**< the number of simultaneous fingers on this touchpad */392Uint16 padding[3];393} SDL_VirtualJoystickTouchpadDesc;394395/**396* The structure that describes a virtual joystick sensor.397*398* \since This struct is available since SDL 3.2.0.399*400* \sa SDL_VirtualJoystickDesc401*/402typedef struct SDL_VirtualJoystickSensorDesc403{404SDL_SensorType type; /**< the type of this sensor */405float rate; /**< the update frequency of this sensor, may be 0.0f */406} SDL_VirtualJoystickSensorDesc;407408/**409* The structure that describes a virtual joystick.410*411* This structure should be initialized using SDL_INIT_INTERFACE(). All412* elements of this structure are optional.413*414* \since This struct is available since SDL 3.2.0.415*416* \sa SDL_AttachVirtualJoystick417* \sa SDL_INIT_INTERFACE418* \sa SDL_VirtualJoystickSensorDesc419* \sa SDL_VirtualJoystickTouchpadDesc420*/421typedef struct SDL_VirtualJoystickDesc422{423Uint32 version; /**< the version of this interface */424Uint16 type; /**< `SDL_JoystickType` */425Uint16 padding; /**< unused */426Uint16 vendor_id; /**< the USB vendor ID of this joystick */427Uint16 product_id; /**< the USB product ID of this joystick */428Uint16 naxes; /**< the number of axes on this joystick */429Uint16 nbuttons; /**< the number of buttons on this joystick */430Uint16 nballs; /**< the number of balls on this joystick */431Uint16 nhats; /**< the number of hats on this joystick */432Uint16 ntouchpads; /**< the number of touchpads on this joystick, requires `touchpads` to point at valid descriptions */433Uint16 nsensors; /**< the number of sensors on this joystick, requires `sensors` to point at valid descriptions */434Uint16 padding2[2]; /**< unused */435Uint32 button_mask; /**< A mask of which buttons are valid for this controller436e.g. (1 << SDL_GAMEPAD_BUTTON_SOUTH) */437Uint32 axis_mask; /**< A mask of which axes are valid for this controller438e.g. (1 << SDL_GAMEPAD_AXIS_LEFTX) */439const char *name; /**< the name of the joystick */440const SDL_VirtualJoystickTouchpadDesc *touchpads; /**< A pointer to an array of touchpad descriptions, required if `ntouchpads` is > 0 */441const SDL_VirtualJoystickSensorDesc *sensors; /**< A pointer to an array of sensor descriptions, required if `nsensors` is > 0 */442443void *userdata; /**< User data pointer passed to callbacks */444void (SDLCALL *Update)(void *userdata); /**< Called when the joystick state should be updated */445void (SDLCALL *SetPlayerIndex)(void *userdata, int player_index); /**< Called when the player index is set */446bool (SDLCALL *Rumble)(void *userdata, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); /**< Implements SDL_RumbleJoystick() */447bool (SDLCALL *RumbleTriggers)(void *userdata, Uint16 left_rumble, Uint16 right_rumble); /**< Implements SDL_RumbleJoystickTriggers() */448bool (SDLCALL *SetLED)(void *userdata, Uint8 red, Uint8 green, Uint8 blue); /**< Implements SDL_SetJoystickLED() */449bool (SDLCALL *SendEffect)(void *userdata, const void *data, int size); /**< Implements SDL_SendJoystickEffect() */450bool (SDLCALL *SetSensorsEnabled)(void *userdata, bool enabled); /**< Implements SDL_SetGamepadSensorEnabled() */451void (SDLCALL *Cleanup)(void *userdata); /**< Cleans up the userdata when the joystick is detached */452} SDL_VirtualJoystickDesc;453454/* Check the size of SDL_VirtualJoystickDesc455*456* If this assert fails, either the compiler is padding to an unexpected size,457* or the interface has been updated and this should be updated to match and458* the code using this interface should be updated to handle the old version.459*/460SDL_COMPILE_TIME_ASSERT(SDL_VirtualJoystickDesc_SIZE,461(sizeof(void *) == 4 && sizeof(SDL_VirtualJoystickDesc) == 84) ||462(sizeof(void *) == 8 && sizeof(SDL_VirtualJoystickDesc) == 136));463464/**465* Attach a new virtual joystick.466*467* \param desc joystick description, initialized using SDL_INIT_INTERFACE().468* \returns the joystick instance ID, or 0 on failure; call SDL_GetError() for469* more information.470*471* \since This function is available since SDL 3.2.0.472*473* \sa SDL_DetachVirtualJoystick474*/475extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_AttachVirtualJoystick(const SDL_VirtualJoystickDesc *desc);476477/**478* Detach a virtual joystick.479*480* \param instance_id the joystick instance ID, previously returned from481* SDL_AttachVirtualJoystick().482* \returns true on success or false on failure; call SDL_GetError() for more483* information.484*485* \since This function is available since SDL 3.2.0.486*487* \sa SDL_AttachVirtualJoystick488*/489extern SDL_DECLSPEC bool SDLCALL SDL_DetachVirtualJoystick(SDL_JoystickID instance_id);490491/**492* Query whether or not a joystick is virtual.493*494* \param instance_id the joystick instance ID.495* \returns true if the joystick is virtual, false otherwise.496*497* \since This function is available since SDL 3.2.0.498*/499extern SDL_DECLSPEC bool SDLCALL SDL_IsJoystickVirtual(SDL_JoystickID instance_id);500501/**502* Set the state of an axis on an opened virtual joystick.503*504* Please note that values set here will not be applied until the next call to505* SDL_UpdateJoysticks, which can either be called directly, or can be called506* indirectly through various other SDL APIs, including, but not limited to507* the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,508* SDL_WaitEvent.509*510* Note that when sending trigger axes, you should scale the value to the full511* range of Sint16. For example, a trigger at rest would have the value of512* `SDL_JOYSTICK_AXIS_MIN`.513*514* \param joystick the virtual joystick on which to set state.515* \param axis the index of the axis on the virtual joystick to update.516* \param value the new value for the specified axis.517* \returns true on success or false on failure; call SDL_GetError() for more518* information.519*520* \since This function is available since SDL 3.2.0.521*/522extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value);523524/**525* Generate ball motion on an opened virtual joystick.526*527* Please note that values set here will not be applied until the next call to528* SDL_UpdateJoysticks, which can either be called directly, or can be called529* indirectly through various other SDL APIs, including, but not limited to530* the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,531* SDL_WaitEvent.532*533* \param joystick the virtual joystick on which to set state.534* \param ball the index of the ball on the virtual joystick to update.535* \param xrel the relative motion on the X axis.536* \param yrel the relative motion on the Y axis.537* \returns true on success or false on failure; call SDL_GetError() for more538* information.539*540* \since This function is available since SDL 3.2.0.541*/542extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualBall(SDL_Joystick *joystick, int ball, Sint16 xrel, Sint16 yrel);543544/**545* Set the state of a button on an opened virtual joystick.546*547* Please note that values set here will not be applied until the next call to548* SDL_UpdateJoysticks, which can either be called directly, or can be called549* indirectly through various other SDL APIs, including, but not limited to550* the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,551* SDL_WaitEvent.552*553* \param joystick the virtual joystick on which to set state.554* \param button the index of the button on the virtual joystick to update.555* \param down true if the button is pressed, false otherwise.556* \returns true on success or false on failure; call SDL_GetError() for more557* information.558*559* \since This function is available since SDL 3.2.0.560*/561extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, bool down);562563/**564* Set the state of a hat on an opened virtual joystick.565*566* Please note that values set here will not be applied until the next call to567* SDL_UpdateJoysticks, which can either be called directly, or can be called568* indirectly through various other SDL APIs, including, but not limited to569* the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,570* SDL_WaitEvent.571*572* \param joystick the virtual joystick on which to set state.573* \param hat the index of the hat on the virtual joystick to update.574* \param value the new value for the specified hat.575* \returns true on success or false on failure; call SDL_GetError() for more576* information.577*578* \since This function is available since SDL 3.2.0.579*/580extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value);581582/**583* Set touchpad finger state on an opened virtual joystick.584*585* Please note that values set here will not be applied until the next call to586* SDL_UpdateJoysticks, which can either be called directly, or can be called587* indirectly through various other SDL APIs, including, but not limited to588* the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,589* SDL_WaitEvent.590*591* \param joystick the virtual joystick on which to set state.592* \param touchpad the index of the touchpad on the virtual joystick to593* update.594* \param finger the index of the finger on the touchpad to set.595* \param down true if the finger is pressed, false if the finger is released.596* \param x the x coordinate of the finger on the touchpad, normalized 0 to 1,597* with the origin in the upper left.598* \param y the y coordinate of the finger on the touchpad, normalized 0 to 1,599* with the origin in the upper left.600* \param pressure the pressure of the finger.601* \returns true on success or false on failure; call SDL_GetError() for more602* information.603*604* \since This function is available since SDL 3.2.0.605*/606extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualTouchpad(SDL_Joystick *joystick, int touchpad, int finger, bool down, float x, float y, float pressure);607608/**609* Send a sensor update for an opened virtual joystick.610*611* Please note that values set here will not be applied until the next call to612* SDL_UpdateJoysticks, which can either be called directly, or can be called613* indirectly through various other SDL APIs, including, but not limited to614* the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,615* SDL_WaitEvent.616*617* \param joystick the virtual joystick on which to set state.618* \param type the type of the sensor on the virtual joystick to update.619* \param sensor_timestamp a 64-bit timestamp in nanoseconds associated with620* the sensor reading.621* \param data the data associated with the sensor reading.622* \param num_values the number of values pointed to by `data`.623* \returns true on success or false on failure; call SDL_GetError() for more624* information.625*626* \since This function is available since SDL 3.2.0.627*/628extern SDL_DECLSPEC bool SDLCALL SDL_SendJoystickVirtualSensorData(SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values);629630/**631* Get the properties associated with a joystick.632*633* The following read-only properties are provided by SDL:634*635* - `SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN`: true if this joystick has an636* LED that has adjustable brightness637* - `SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN`: true if this joystick has an LED638* that has adjustable color639* - `SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN`: true if this joystick has a640* player LED641* - `SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN`: true if this joystick has642* left/right rumble643* - `SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN`: true if this joystick has644* simple trigger rumble645*646* \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().647* \returns a valid property ID on success or 0 on failure; call648* SDL_GetError() for more information.649*650* \since This function is available since SDL 3.2.0.651*/652extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetJoystickProperties(SDL_Joystick *joystick);653654#define SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN "SDL.joystick.cap.mono_led"655#define SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN "SDL.joystick.cap.rgb_led"656#define SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN "SDL.joystick.cap.player_led"657#define SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN "SDL.joystick.cap.rumble"658#define SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN "SDL.joystick.cap.trigger_rumble"659660/**661* Get the implementation dependent name of a joystick.662*663* \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().664* \returns the name of the selected joystick. If no name can be found, this665* function returns NULL; call SDL_GetError() for more information.666*667* \since This function is available since SDL 3.2.0.668*669* \sa SDL_GetJoystickNameForID670*/671extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickName(SDL_Joystick *joystick);672673/**674* Get the implementation dependent path of a joystick.675*676* \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().677* \returns the path of the selected joystick. If no path can be found, this678* function returns NULL; call SDL_GetError() for more information.679*680* \since This function is available since SDL 3.2.0.681*682* \sa SDL_GetJoystickPathForID683*/684extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickPath(SDL_Joystick *joystick);685686/**687* Get the player index of an opened joystick.688*689* For XInput controllers this returns the XInput user index. Many joysticks690* will not be able to supply this information.691*692* \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().693* \returns the player index, or -1 if it's not available.694*695* \since This function is available since SDL 3.2.0.696*697* \sa SDL_SetJoystickPlayerIndex698*/699extern SDL_DECLSPEC int SDLCALL SDL_GetJoystickPlayerIndex(SDL_Joystick *joystick);700701/**702* Set the player index of an opened joystick.703*704* \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().705* \param player_index player index to assign to this joystick, or -1 to clear706* the player index and turn off player LEDs.707* \returns true on success or false on failure; call SDL_GetError() for more708* information.709*710* \since This function is available since SDL 3.2.0.711*712* \sa SDL_GetJoystickPlayerIndex713*/714extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickPlayerIndex(SDL_Joystick *joystick, int player_index);715716/**717* Get the implementation-dependent GUID for the joystick.718*719* This function requires an open joystick.720*721* \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().722* \returns the GUID of the given joystick. If called on an invalid index,723* this function returns a zero GUID; call SDL_GetError() for more724* information.725*726* \since This function is available since SDL 3.2.0.727*728* \sa SDL_GetJoystickGUIDForID729* \sa SDL_GUIDToString730*/731extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GetJoystickGUID(SDL_Joystick *joystick);732733/**734* Get the USB vendor ID of an opened joystick, if available.735*736* If the vendor ID isn't available this function returns 0.737*738* \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().739* \returns the USB vendor ID of the selected joystick, or 0 if unavailable.740*741* \since This function is available since SDL 3.2.0.742*743* \sa SDL_GetJoystickVendorForID744*/745extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickVendor(SDL_Joystick *joystick);746747/**748* Get the USB product ID of an opened joystick, if available.749*750* If the product ID isn't available this function returns 0.751*752* \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().753* \returns the USB product ID of the selected joystick, or 0 if unavailable.754*755* \since This function is available since SDL 3.2.0.756*757* \sa SDL_GetJoystickProductForID758*/759extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProduct(SDL_Joystick *joystick);760761/**762* Get the product version of an opened joystick, if available.763*764* If the product version isn't available this function returns 0.765*766* \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().767* \returns the product version of the selected joystick, or 0 if unavailable.768*769* \since This function is available since SDL 3.2.0.770*771* \sa SDL_GetJoystickProductVersionForID772*/773extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductVersion(SDL_Joystick *joystick);774775/**776* Get the firmware version of an opened joystick, if available.777*778* If the firmware version isn't available this function returns 0.779*780* \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().781* \returns the firmware version of the selected joystick, or 0 if782* unavailable.783*784* \since This function is available since SDL 3.2.0.785*/786extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickFirmwareVersion(SDL_Joystick *joystick);787788/**789* Get the serial number of an opened joystick, if available.790*791* Returns the serial number of the joystick, or NULL if it is not available.792*793* \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().794* \returns the serial number of the selected joystick, or NULL if795* unavailable.796*797* \since This function is available since SDL 3.2.0.798*/799extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickSerial(SDL_Joystick *joystick);800801/**802* Get the type of an opened joystick.803*804* \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().805* \returns the SDL_JoystickType of the selected joystick.806*807* \since This function is available since SDL 3.2.0.808*809* \sa SDL_GetJoystickTypeForID810*/811extern SDL_DECLSPEC SDL_JoystickType SDLCALL SDL_GetJoystickType(SDL_Joystick *joystick);812813/**814* Get the device information encoded in a SDL_GUID structure.815*816* \param guid the SDL_GUID you wish to get info about.817* \param vendor a pointer filled in with the device VID, or 0 if not818* available.819* \param product a pointer filled in with the device PID, or 0 if not820* available.821* \param version a pointer filled in with the device version, or 0 if not822* available.823* \param crc16 a pointer filled in with a CRC used to distinguish different824* products with the same VID/PID, or 0 if not available.825*826* \since This function is available since SDL 3.2.0.827*828* \sa SDL_GetJoystickGUIDForID829*/830extern SDL_DECLSPEC void SDLCALL SDL_GetJoystickGUIDInfo(SDL_GUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version, Uint16 *crc16);831832/**833* Get the status of a specified joystick.834*835* \param joystick the joystick to query.836* \returns true if the joystick has been opened, false if it has not; call837* SDL_GetError() for more information.838*839* \since This function is available since SDL 3.2.0.840*/841extern SDL_DECLSPEC bool SDLCALL SDL_JoystickConnected(SDL_Joystick *joystick);842843/**844* Get the instance ID of an opened joystick.845*846* \param joystick an SDL_Joystick structure containing joystick information.847* \returns the instance ID of the specified joystick on success or 0 on848* failure; call SDL_GetError() for more information.849*850* \since This function is available since SDL 3.2.0.851*/852extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_GetJoystickID(SDL_Joystick *joystick);853854/**855* Get the number of general axis controls on a joystick.856*857* Often, the directional pad on a game controller will either look like 4858* separate buttons or a POV hat, and not axes, but all of this is up to the859* device and platform.860*861* \param joystick an SDL_Joystick structure containing joystick information.862* \returns the number of axis controls/number of axes on success or -1 on863* failure; call SDL_GetError() for more information.864*865* \since This function is available since SDL 3.2.0.866*867* \sa SDL_GetJoystickAxis868* \sa SDL_GetNumJoystickBalls869* \sa SDL_GetNumJoystickButtons870* \sa SDL_GetNumJoystickHats871*/872extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickAxes(SDL_Joystick *joystick);873874/**875* Get the number of trackballs on a joystick.876*877* Joystick trackballs have only relative motion events associated with them878* and their state cannot be polled.879*880* Most joysticks do not have trackballs.881*882* \param joystick an SDL_Joystick structure containing joystick information.883* \returns the number of trackballs on success or -1 on failure; call884* SDL_GetError() for more information.885*886* \since This function is available since SDL 3.2.0.887*888* \sa SDL_GetJoystickBall889* \sa SDL_GetNumJoystickAxes890* \sa SDL_GetNumJoystickButtons891* \sa SDL_GetNumJoystickHats892*/893extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickBalls(SDL_Joystick *joystick);894895/**896* Get the number of POV hats on a joystick.897*898* \param joystick an SDL_Joystick structure containing joystick information.899* \returns the number of POV hats on success or -1 on failure; call900* SDL_GetError() for more information.901*902* \since This function is available since SDL 3.2.0.903*904* \sa SDL_GetJoystickHat905* \sa SDL_GetNumJoystickAxes906* \sa SDL_GetNumJoystickBalls907* \sa SDL_GetNumJoystickButtons908*/909extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickHats(SDL_Joystick *joystick);910911/**912* Get the number of buttons on a joystick.913*914* \param joystick an SDL_Joystick structure containing joystick information.915* \returns the number of buttons on success or -1 on failure; call916* SDL_GetError() for more information.917*918* \since This function is available since SDL 3.2.0.919*920* \sa SDL_GetJoystickButton921* \sa SDL_GetNumJoystickAxes922* \sa SDL_GetNumJoystickBalls923* \sa SDL_GetNumJoystickHats924*/925extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickButtons(SDL_Joystick *joystick);926927/**928* Set the state of joystick event processing.929*930* If joystick events are disabled, you must call SDL_UpdateJoysticks()931* yourself and check the state of the joystick when you want joystick932* information.933*934* \param enabled whether to process joystick events or not.935*936* \since This function is available since SDL 3.2.0.937*938* \sa SDL_JoystickEventsEnabled939* \sa SDL_UpdateJoysticks940*/941extern SDL_DECLSPEC void SDLCALL SDL_SetJoystickEventsEnabled(bool enabled);942943/**944* Query the state of joystick event processing.945*946* If joystick events are disabled, you must call SDL_UpdateJoysticks()947* yourself and check the state of the joystick when you want joystick948* information.949*950* \returns true if joystick events are being processed, false otherwise.951*952* \since This function is available since SDL 3.2.0.953*954* \sa SDL_SetJoystickEventsEnabled955*/956extern SDL_DECLSPEC bool SDLCALL SDL_JoystickEventsEnabled(void);957958/**959* Update the current state of the open joysticks.960*961* This is called automatically by the event loop if any joystick events are962* enabled.963*964* \since This function is available since SDL 3.2.0.965*/966extern SDL_DECLSPEC void SDLCALL SDL_UpdateJoysticks(void);967968/**969* Get the current state of an axis control on a joystick.970*971* SDL makes no promises about what part of the joystick any given axis refers972* to. Your game should have some sort of configuration UI to let users973* specify what each axis should be bound to. Alternately, SDL's higher-level974* Game Controller API makes a great effort to apply order to this lower-level975* interface, so you know that a specific axis is the "left thumb stick," etc.976*977* The value returned by SDL_GetJoystickAxis() is a signed integer (-32768 to978* 32767) representing the current position of the axis. It may be necessary979* to impose certain tolerances on these values to account for jitter.980*981* \param joystick an SDL_Joystick structure containing joystick information.982* \param axis the axis to query; the axis indices start at index 0.983* \returns a 16-bit signed integer representing the current position of the984* axis or 0 on failure; call SDL_GetError() for more information.985*986* \since This function is available since SDL 3.2.0.987*988* \sa SDL_GetNumJoystickAxes989*/990extern SDL_DECLSPEC Sint16 SDLCALL SDL_GetJoystickAxis(SDL_Joystick *joystick, int axis);991992/**993* Get the initial state of an axis control on a joystick.994*995* The state is a value ranging from -32768 to 32767.996*997* The axis indices start at index 0.998*999* \param joystick an SDL_Joystick structure containing joystick information.1000* \param axis the axis to query; the axis indices start at index 0.1001* \param state upon return, the initial value is supplied here.1002* \returns true if this axis has any initial value, or false if not.1003*1004* \since This function is available since SDL 3.2.0.1005*/1006extern SDL_DECLSPEC bool SDLCALL SDL_GetJoystickAxisInitialState(SDL_Joystick *joystick, int axis, Sint16 *state);10071008/**1009* Get the ball axis change since the last poll.1010*1011* Trackballs can only return relative motion since the last call to1012* SDL_GetJoystickBall(), these motion deltas are placed into `dx` and `dy`.1013*1014* Most joysticks do not have trackballs.1015*1016* \param joystick the SDL_Joystick to query.1017* \param ball the ball index to query; ball indices start at index 0.1018* \param dx stores the difference in the x axis position since the last poll.1019* \param dy stores the difference in the y axis position since the last poll.1020* \returns true on success or false on failure; call SDL_GetError() for more1021* information.1022*1023* \since This function is available since SDL 3.2.0.1024*1025* \sa SDL_GetNumJoystickBalls1026*/1027extern SDL_DECLSPEC bool SDLCALL SDL_GetJoystickBall(SDL_Joystick *joystick, int ball, int *dx, int *dy);10281029/**1030* Get the current state of a POV hat on a joystick.1031*1032* The returned value will be one of the `SDL_HAT_*` values.1033*1034* \param joystick an SDL_Joystick structure containing joystick information.1035* \param hat the hat index to get the state from; indices start at index 0.1036* \returns the current hat position.1037*1038* \since This function is available since SDL 3.2.0.1039*1040* \sa SDL_GetNumJoystickHats1041*/1042extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetJoystickHat(SDL_Joystick *joystick, int hat);10431044#define SDL_HAT_CENTERED 0x00u1045#define SDL_HAT_UP 0x01u1046#define SDL_HAT_RIGHT 0x02u1047#define SDL_HAT_DOWN 0x04u1048#define SDL_HAT_LEFT 0x08u1049#define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)1050#define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)1051#define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)1052#define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)10531054/**1055* Get the current state of a button on a joystick.1056*1057* \param joystick an SDL_Joystick structure containing joystick information.1058* \param button the button index to get the state from; indices start at1059* index 0.1060* \returns true if the button is pressed, false otherwise.1061*1062* \since This function is available since SDL 3.2.0.1063*1064* \sa SDL_GetNumJoystickButtons1065*/1066extern SDL_DECLSPEC bool SDLCALL SDL_GetJoystickButton(SDL_Joystick *joystick, int button);10671068/**1069* Start a rumble effect.1070*1071* Each call to this function cancels any previous rumble effect, and calling1072* it with 0 intensity stops any rumbling.1073*1074* This function requires you to process SDL events or call1075* SDL_UpdateJoysticks() to update rumble state.1076*1077* \param joystick the joystick to vibrate.1078* \param low_frequency_rumble the intensity of the low frequency (left)1079* rumble motor, from 0 to 0xFFFF.1080* \param high_frequency_rumble the intensity of the high frequency (right)1081* rumble motor, from 0 to 0xFFFF.1082* \param duration_ms the duration of the rumble effect, in milliseconds.1083* \returns true, or false if rumble isn't supported on this joystick.1084*1085* \since This function is available since SDL 3.2.0.1086*/1087extern SDL_DECLSPEC bool SDLCALL SDL_RumbleJoystick(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);10881089/**1090* Start a rumble effect in the joystick's triggers.1091*1092* Each call to this function cancels any previous trigger rumble effect, and1093* calling it with 0 intensity stops any rumbling.1094*1095* Note that this is rumbling of the _triggers_ and not the game controller as1096* a whole. This is currently only supported on Xbox One controllers. If you1097* want the (more common) whole-controller rumble, use SDL_RumbleJoystick()1098* instead.1099*1100* This function requires you to process SDL events or call1101* SDL_UpdateJoysticks() to update rumble state.1102*1103* \param joystick the joystick to vibrate.1104* \param left_rumble the intensity of the left trigger rumble motor, from 01105* to 0xFFFF.1106* \param right_rumble the intensity of the right trigger rumble motor, from 01107* to 0xFFFF.1108* \param duration_ms the duration of the rumble effect, in milliseconds.1109* \returns true on success or false on failure; call SDL_GetError() for more1110* information.1111*1112* \since This function is available since SDL 3.2.0.1113*1114* \sa SDL_RumbleJoystick1115*/1116extern SDL_DECLSPEC bool SDLCALL SDL_RumbleJoystickTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);11171118/**1119* Update a joystick's LED color.1120*1121* An example of a joystick LED is the light on the back of a PlayStation 4's1122* DualShock 4 controller.1123*1124* For joysticks with a single color LED, the maximum of the RGB values will1125* be used as the LED brightness.1126*1127* \param joystick the joystick to update.1128* \param red the intensity of the red LED.1129* \param green the intensity of the green LED.1130* \param blue the intensity of the blue LED.1131* \returns true on success or false on failure; call SDL_GetError() for more1132* information.1133*1134* \since This function is available since SDL 3.2.0.1135*/1136extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);11371138/**1139* Send a joystick specific effect packet.1140*1141* \param joystick the joystick to affect.1142* \param data the data to send to the joystick.1143* \param size the size of the data to send to the joystick.1144* \returns true on success or false on failure; call SDL_GetError() for more1145* information.1146*1147* \since This function is available since SDL 3.2.0.1148*/1149extern SDL_DECLSPEC bool SDLCALL SDL_SendJoystickEffect(SDL_Joystick *joystick, const void *data, int size);11501151/**1152* Close a joystick previously opened with SDL_OpenJoystick().1153*1154* \param joystick the joystick device to close.1155*1156* \since This function is available since SDL 3.2.0.1157*1158* \sa SDL_OpenJoystick1159*/1160extern SDL_DECLSPEC void SDLCALL SDL_CloseJoystick(SDL_Joystick *joystick);11611162/**1163* Get the connection state of a joystick.1164*1165* \param joystick the joystick to query.1166* \returns the connection state on success or1167* `SDL_JOYSTICK_CONNECTION_INVALID` on failure; call SDL_GetError()1168* for more information.1169*1170* \since This function is available since SDL 3.2.0.1171*/1172extern SDL_DECLSPEC SDL_JoystickConnectionState SDLCALL SDL_GetJoystickConnectionState(SDL_Joystick *joystick);11731174/**1175* Get the battery state of a joystick.1176*1177* You should never take a battery status as absolute truth. Batteries1178* (especially failing batteries) are delicate hardware, and the values1179* reported here are best estimates based on what that hardware reports. It's1180* not uncommon for older batteries to lose stored power much faster than it1181* reports, or completely drain when reporting it has 20 percent left, etc.1182*1183* \param joystick the joystick to query.1184* \param percent a pointer filled in with the percentage of battery life1185* left, between 0 and 100, or NULL to ignore. This will be1186* filled in with -1 we can't determine a value or there is no1187* battery.1188* \returns the current battery state or `SDL_POWERSTATE_ERROR` on failure;1189* call SDL_GetError() for more information.1190*1191* \since This function is available since SDL 3.2.0.1192*/1193extern SDL_DECLSPEC SDL_PowerState SDLCALL SDL_GetJoystickPowerInfo(SDL_Joystick *joystick, int *percent);11941195/* Ends C function definitions when using C++ */1196#ifdef __cplusplus1197}1198#endif1199#include <SDL3/SDL_close_code.h>12001201#endif /* SDL_joystick_h_ */120212031204