SDL_gamepad.h 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * # CategoryGamepad
  20. *
  21. * SDL provides a low-level joystick API, which just treats joysticks as an
  22. * arbitrary pile of buttons, axes, and hat switches. If you're planning to
  23. * write your own control configuration screen, this can give you a lot of
  24. * flexibility, but that's a lot of work, and most things that we consider
  25. * "joysticks" now are actually console-style gamepads. So SDL provides the
  26. * gamepad API on top of the lower-level joystick functionality.
  27. *
  28. * The difference betweena joystick and a gamepad is that a gamepad tells you
  29. * _where_ a button or axis is on the device. You don't speak to gamepads in
  30. * terms of arbitrary numbers like "button 3" or "axis 2" but in standard
  31. * locations: the d-pad, the shoulder buttons, triggers, A/B/X/Y (or
  32. * X/O/Square/Triangle, if you will).
  33. *
  34. * One turns a joystick into a gamepad by providing a magic configuration
  35. * string, which tells SDL the details of a specific device: when you see this
  36. * specific hardware, if button 2 gets pressed, this is actually D-Pad Up,
  37. * etc.
  38. *
  39. * SDL has many popular controllers configured out of the box, and users can
  40. * add their own controller details through an environment variable if it's
  41. * otherwise unknown to SDL.
  42. *
  43. * In order to use these functions, SDL_Init() must have been called with the
  44. * SDL_INIT_GAMEPAD flag. This causes SDL to scan the system for gamepads, and
  45. * load appropriate drivers.
  46. *
  47. * If you would like to receive gamepad updates while the application is in
  48. * the background, you should set the following hint before calling
  49. * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
  50. *
  51. * Gamepads support various optional features such as rumble, color LEDs,
  52. * touchpad, gyro, etc. The support for these features varies depending on the
  53. * controller and OS support available. You can check for LED and rumble
  54. * capabilities at runtime by calling SDL_GetGamepadProperties() and checking
  55. * the various capability properties. You can check for touchpad by calling
  56. * SDL_GetNumGamepadTouchpads() and check for gyro and accelerometer by
  57. * calling SDL_GamepadHasSensor().
  58. *
  59. * By default SDL will try to use the most capable driver available, but you
  60. * can tune which OS drivers to use with the various joystick hints in
  61. * SDL_hints.h.
  62. */
  63. #ifndef SDL_gamepad_h_
  64. #define SDL_gamepad_h_
  65. #include <SDL3/SDL_stdinc.h>
  66. #include <SDL3/SDL_error.h>
  67. #include <SDL3/SDL_guid.h>
  68. #include <SDL3/SDL_iostream.h>
  69. #include <SDL3/SDL_joystick.h>
  70. #include <SDL3/SDL_power.h>
  71. #include <SDL3/SDL_properties.h>
  72. #include <SDL3/SDL_sensor.h>
  73. #include <SDL3/SDL_begin_code.h>
  74. /* Set up for C function definitions, even when using C++ */
  75. #ifdef __cplusplus
  76. extern "C" {
  77. #endif
  78. /**
  79. * The structure used to identify an SDL gamepad
  80. *
  81. * \since This struct is available since SDL 3.1.3.
  82. */
  83. typedef struct SDL_Gamepad SDL_Gamepad;
  84. /**
  85. * Standard gamepad types.
  86. *
  87. * This type does not necessarily map to first-party controllers from
  88. * Microsoft/Sony/Nintendo; in many cases, third-party controllers can report
  89. * as these, either because they were designed for a specific console, or they
  90. * simply most closely match that console's controllers (does it have A/B/X/Y
  91. * buttons or X/O/Square/Triangle? Does it have a touchpad? etc).
  92. */
  93. typedef enum SDL_GamepadType
  94. {
  95. SDL_GAMEPAD_TYPE_UNKNOWN = 0,
  96. SDL_GAMEPAD_TYPE_STANDARD,
  97. SDL_GAMEPAD_TYPE_XBOX360,
  98. SDL_GAMEPAD_TYPE_XBOXONE,
  99. SDL_GAMEPAD_TYPE_PS3,
  100. SDL_GAMEPAD_TYPE_PS4,
  101. SDL_GAMEPAD_TYPE_PS5,
  102. SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO,
  103. SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT,
  104. SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT,
  105. SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_PAIR,
  106. SDL_GAMEPAD_TYPE_COUNT
  107. } SDL_GamepadType;
  108. /**
  109. * The list of buttons available on a gamepad
  110. *
  111. * For controllers that use a diamond pattern for the face buttons, the
  112. * south/east/west/north buttons below correspond to the locations in the
  113. * diamond pattern. For Xbox controllers, this would be A/B/X/Y, for Nintendo
  114. * Switch controllers, this would be B/A/Y/X, for PlayStation controllers this
  115. * would be Cross/Circle/Square/Triangle.
  116. *
  117. * For controllers that don't use a diamond pattern for the face buttons, the
  118. * south/east/west/north buttons indicate the buttons labeled A, B, C, D, or
  119. * 1, 2, 3, 4, or for controllers that aren't labeled, they are the primary,
  120. * secondary, etc. buttons.
  121. *
  122. * The activate action is often the south button and the cancel action is
  123. * often the east button, but in some regions this is reversed, so your game
  124. * should allow remapping actions based on user preferences.
  125. *
  126. * You can query the labels for the face buttons using
  127. * SDL_GetGamepadButtonLabel()
  128. *
  129. * \since This enum is available since SDL 3.1.3.
  130. */
  131. typedef enum SDL_GamepadButton
  132. {
  133. SDL_GAMEPAD_BUTTON_INVALID = -1,
  134. SDL_GAMEPAD_BUTTON_SOUTH, /**< Bottom face button (e.g. Xbox A button) */
  135. SDL_GAMEPAD_BUTTON_EAST, /**< Right face button (e.g. Xbox B button) */
  136. SDL_GAMEPAD_BUTTON_WEST, /**< Left face button (e.g. Xbox X button) */
  137. SDL_GAMEPAD_BUTTON_NORTH, /**< Top face button (e.g. Xbox Y button) */
  138. SDL_GAMEPAD_BUTTON_BACK,
  139. SDL_GAMEPAD_BUTTON_GUIDE,
  140. SDL_GAMEPAD_BUTTON_START,
  141. SDL_GAMEPAD_BUTTON_LEFT_STICK,
  142. SDL_GAMEPAD_BUTTON_RIGHT_STICK,
  143. SDL_GAMEPAD_BUTTON_LEFT_SHOULDER,
  144. SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER,
  145. SDL_GAMEPAD_BUTTON_DPAD_UP,
  146. SDL_GAMEPAD_BUTTON_DPAD_DOWN,
  147. SDL_GAMEPAD_BUTTON_DPAD_LEFT,
  148. SDL_GAMEPAD_BUTTON_DPAD_RIGHT,
  149. SDL_GAMEPAD_BUTTON_MISC1, /**< Additional button (e.g. Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Amazon Luna microphone button, Google Stadia capture button) */
  150. SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1, /**< Upper or primary paddle, under your right hand (e.g. Xbox Elite paddle P1) */
  151. SDL_GAMEPAD_BUTTON_LEFT_PADDLE1, /**< Upper or primary paddle, under your left hand (e.g. Xbox Elite paddle P3) */
  152. SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2, /**< Lower or secondary paddle, under your right hand (e.g. Xbox Elite paddle P2) */
  153. SDL_GAMEPAD_BUTTON_LEFT_PADDLE2, /**< Lower or secondary paddle, under your left hand (e.g. Xbox Elite paddle P4) */
  154. SDL_GAMEPAD_BUTTON_TOUCHPAD, /**< PS4/PS5 touchpad button */
  155. SDL_GAMEPAD_BUTTON_MISC2, /**< Additional button */
  156. SDL_GAMEPAD_BUTTON_MISC3, /**< Additional button */
  157. SDL_GAMEPAD_BUTTON_MISC4, /**< Additional button */
  158. SDL_GAMEPAD_BUTTON_MISC5, /**< Additional button */
  159. SDL_GAMEPAD_BUTTON_MISC6, /**< Additional button */
  160. SDL_GAMEPAD_BUTTON_COUNT
  161. } SDL_GamepadButton;
  162. /**
  163. * The set of gamepad button labels
  164. *
  165. * This isn't a complete set, just the face buttons to make it easy to show
  166. * button prompts.
  167. *
  168. * For a complete set, you should look at the button and gamepad type and have
  169. * a set of symbols that work well with your art style.
  170. *
  171. * \since This enum is available since SDL 3.1.3.
  172. */
  173. typedef enum SDL_GamepadButtonLabel
  174. {
  175. SDL_GAMEPAD_BUTTON_LABEL_UNKNOWN,
  176. SDL_GAMEPAD_BUTTON_LABEL_A,
  177. SDL_GAMEPAD_BUTTON_LABEL_B,
  178. SDL_GAMEPAD_BUTTON_LABEL_X,
  179. SDL_GAMEPAD_BUTTON_LABEL_Y,
  180. SDL_GAMEPAD_BUTTON_LABEL_CROSS,
  181. SDL_GAMEPAD_BUTTON_LABEL_CIRCLE,
  182. SDL_GAMEPAD_BUTTON_LABEL_SQUARE,
  183. SDL_GAMEPAD_BUTTON_LABEL_TRIANGLE
  184. } SDL_GamepadButtonLabel;
  185. /**
  186. * The list of axes available on a gamepad
  187. *
  188. * Thumbstick axis values range from SDL_JOYSTICK_AXIS_MIN to
  189. * SDL_JOYSTICK_AXIS_MAX, and are centered within ~8000 of zero, though
  190. * advanced UI will allow users to set or autodetect the dead zone, which
  191. * varies between gamepads.
  192. *
  193. * Trigger axis values range from 0 (released) to SDL_JOYSTICK_AXIS_MAX (fully
  194. * pressed) when reported by SDL_GetGamepadAxis(). Note that this is not the
  195. * same range that will be reported by the lower-level SDL_GetJoystickAxis().
  196. *
  197. * \since This enum is available since SDL 3.1.3.
  198. */
  199. typedef enum SDL_GamepadAxis
  200. {
  201. SDL_GAMEPAD_AXIS_INVALID = -1,
  202. SDL_GAMEPAD_AXIS_LEFTX,
  203. SDL_GAMEPAD_AXIS_LEFTY,
  204. SDL_GAMEPAD_AXIS_RIGHTX,
  205. SDL_GAMEPAD_AXIS_RIGHTY,
  206. SDL_GAMEPAD_AXIS_LEFT_TRIGGER,
  207. SDL_GAMEPAD_AXIS_RIGHT_TRIGGER,
  208. SDL_GAMEPAD_AXIS_COUNT
  209. } SDL_GamepadAxis;
  210. /**
  211. * Types of gamepad control bindings.
  212. *
  213. * A gamepad is a collection of bindings that map arbitrary joystick buttons,
  214. * axes and hat switches to specific positions on a generic console-style
  215. * gamepad. This enum is used as part of SDL_GamepadBinding to specify those
  216. * mappings.
  217. *
  218. * \since This enum is available since SDL 3.1.3.
  219. */
  220. typedef enum SDL_GamepadBindingType
  221. {
  222. SDL_GAMEPAD_BINDTYPE_NONE = 0,
  223. SDL_GAMEPAD_BINDTYPE_BUTTON,
  224. SDL_GAMEPAD_BINDTYPE_AXIS,
  225. SDL_GAMEPAD_BINDTYPE_HAT
  226. } SDL_GamepadBindingType;
  227. /**
  228. * A mapping between one joystick input to a gamepad control.
  229. *
  230. * A gamepad has a collection of several bindings, to say, for example, when
  231. * joystick button number 5 is pressed, that should be treated like the
  232. * gamepad's "start" button.
  233. *
  234. * SDL has these bindings built-in for many popular controllers, and can add
  235. * more with a simple text string. Those strings are parsed into a collection
  236. * of these structs to make it easier to operate on the data.
  237. *
  238. * \since This struct is available since SDL 3.1.3.
  239. *
  240. * \sa SDL_GetGamepadBindings
  241. */
  242. typedef struct SDL_GamepadBinding
  243. {
  244. SDL_GamepadBindingType input_type;
  245. union
  246. {
  247. int button;
  248. struct
  249. {
  250. int axis;
  251. int axis_min;
  252. int axis_max;
  253. } axis;
  254. struct
  255. {
  256. int hat;
  257. int hat_mask;
  258. } hat;
  259. } input;
  260. SDL_GamepadBindingType output_type;
  261. union
  262. {
  263. SDL_GamepadButton button;
  264. struct
  265. {
  266. SDL_GamepadAxis axis;
  267. int axis_min;
  268. int axis_max;
  269. } axis;
  270. } output;
  271. } SDL_GamepadBinding;
  272. /**
  273. * Add support for gamepads that SDL is unaware of or change the binding of an
  274. * existing gamepad.
  275. *
  276. * The mapping string has the format "GUID,name,mapping", where GUID is the
  277. * string value from SDL_GUIDToString(), name is the human readable string for
  278. * the device and mappings are gamepad mappings to joystick ones. Under
  279. * Windows there is a reserved GUID of "xinput" that covers all XInput
  280. * devices. The mapping format for joystick is:
  281. *
  282. * - `bX`: a joystick button, index X
  283. * - `hX.Y`: hat X with value Y
  284. * - `aX`: axis X of the joystick
  285. *
  286. * Buttons can be used as a gamepad axes and vice versa.
  287. *
  288. * If a device with this GUID is already plugged in, SDL will generate an
  289. * SDL_EVENT_GAMEPAD_ADDED event.
  290. *
  291. * This string shows an example of a valid mapping for a gamepad:
  292. *
  293. * ```c
  294. * "341a3608000000000000504944564944,Afterglow PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7"
  295. * ```
  296. *
  297. * \param mapping the mapping string.
  298. * \returns 1 if a new mapping is added, 0 if an existing mapping is updated,
  299. * -1 on failure; call SDL_GetError() for more information.
  300. *
  301. * \threadsafety It is safe to call this function from any thread.
  302. *
  303. * \since This function is available since SDL 3.1.3.
  304. *
  305. * \sa SDL_AddGamepadMappingsFromFile
  306. * \sa SDL_AddGamepadMappingsFromIO
  307. * \sa SDL_GetGamepadMapping
  308. * \sa SDL_GetGamepadMappingForGUID
  309. * \sa SDL_HINT_GAMECONTROLLERCONFIG
  310. * \sa SDL_HINT_GAMECONTROLLERCONFIG_FILE
  311. * \sa SDL_EVENT_GAMEPAD_ADDED
  312. */
  313. extern SDL_DECLSPEC int SDLCALL SDL_AddGamepadMapping(const char *mapping);
  314. /**
  315. * Load a set of gamepad mappings from an SDL_IOStream.
  316. *
  317. * You can call this function several times, if needed, to load different
  318. * database files.
  319. *
  320. * If a new mapping is loaded for an already known gamepad GUID, the later
  321. * version will overwrite the one currently loaded.
  322. *
  323. * Any new mappings for already plugged in controllers will generate
  324. * SDL_EVENT_GAMEPAD_ADDED events.
  325. *
  326. * Mappings not belonging to the current platform or with no platform field
  327. * specified will be ignored (i.e. mappings for Linux will be ignored in
  328. * Windows, etc).
  329. *
  330. * This function will load the text database entirely in memory before
  331. * processing it, so take this into consideration if you are in a memory
  332. * constrained environment.
  333. *
  334. * \param src the data stream for the mappings to be added.
  335. * \param closeio if true, calls SDL_CloseIO() on `src` before returning, even
  336. * in the case of an error.
  337. * \returns the number of mappings added or -1 on failure; call SDL_GetError()
  338. * for more information.
  339. *
  340. * \threadsafety It is safe to call this function from any thread.
  341. *
  342. * \since This function is available since SDL 3.1.3.
  343. *
  344. * \sa SDL_AddGamepadMapping
  345. * \sa SDL_AddGamepadMappingsFromFile
  346. * \sa SDL_GetGamepadMapping
  347. * \sa SDL_GetGamepadMappingForGUID
  348. * \sa SDL_HINT_GAMECONTROLLERCONFIG
  349. * \sa SDL_HINT_GAMECONTROLLERCONFIG_FILE
  350. * \sa SDL_EVENT_GAMEPAD_ADDED
  351. */
  352. extern SDL_DECLSPEC int SDLCALL SDL_AddGamepadMappingsFromIO(SDL_IOStream *src, bool closeio);
  353. /**
  354. * Load a set of gamepad mappings from a file.
  355. *
  356. * You can call this function several times, if needed, to load different
  357. * database files.
  358. *
  359. * If a new mapping is loaded for an already known gamepad GUID, the later
  360. * version will overwrite the one currently loaded.
  361. *
  362. * Any new mappings for already plugged in controllers will generate
  363. * SDL_EVENT_GAMEPAD_ADDED events.
  364. *
  365. * Mappings not belonging to the current platform or with no platform field
  366. * specified will be ignored (i.e. mappings for Linux will be ignored in
  367. * Windows, etc).
  368. *
  369. * \param file the mappings file to load.
  370. * \returns the number of mappings added or -1 on failure; call SDL_GetError()
  371. * for more information.
  372. *
  373. * \threadsafety It is safe to call this function from any thread.
  374. *
  375. * \since This function is available since SDL 3.1.3.
  376. *
  377. * \sa SDL_AddGamepadMapping
  378. * \sa SDL_AddGamepadMappingsFromIO
  379. * \sa SDL_GetGamepadMapping
  380. * \sa SDL_GetGamepadMappingForGUID
  381. * \sa SDL_HINT_GAMECONTROLLERCONFIG
  382. * \sa SDL_HINT_GAMECONTROLLERCONFIG_FILE
  383. * \sa SDL_EVENT_GAMEPAD_ADDED
  384. */
  385. extern SDL_DECLSPEC int SDLCALL SDL_AddGamepadMappingsFromFile(const char *file);
  386. /**
  387. * Reinitialize the SDL mapping database to its initial state.
  388. *
  389. * This will generate gamepad events as needed if device mappings change.
  390. *
  391. * \returns true on success or false on failure; call SDL_GetError() for more
  392. * information.
  393. *
  394. * \since This function is available since SDL 3.1.3.
  395. */
  396. extern SDL_DECLSPEC bool SDLCALL SDL_ReloadGamepadMappings(void);
  397. /**
  398. * Get the current gamepad mappings.
  399. *
  400. * \param count a pointer filled in with the number of mappings returned, can
  401. * be NULL.
  402. * \returns an array of the mapping strings, NULL-terminated, or NULL on
  403. * failure; call SDL_GetError() for more information. This is a
  404. * single allocation that should be freed with SDL_free() when it is
  405. * no longer needed.
  406. *
  407. * \since This function is available since SDL 3.1.3.
  408. */
  409. extern SDL_DECLSPEC char ** SDLCALL SDL_GetGamepadMappings(int *count);
  410. /**
  411. * Get the gamepad mapping string for a given GUID.
  412. *
  413. * \param guid a structure containing the GUID for which a mapping is desired.
  414. * \returns a mapping string or NULL on failure; call SDL_GetError() for more
  415. * information. This should be freed with SDL_free() when it is no
  416. * longer needed.
  417. *
  418. * \since This function is available since SDL 3.1.3.
  419. *
  420. * \sa SDL_GetJoystickGUIDForID
  421. * \sa SDL_GetJoystickGUID
  422. */
  423. extern SDL_DECLSPEC char * SDLCALL SDL_GetGamepadMappingForGUID(SDL_GUID guid);
  424. /**
  425. * Get the current mapping of a gamepad.
  426. *
  427. * Details about mappings are discussed with SDL_AddGamepadMapping().
  428. *
  429. * \param gamepad the gamepad you want to get the current mapping for.
  430. * \returns a string that has the gamepad's mapping or NULL if no mapping is
  431. * available; call SDL_GetError() for more information. This should
  432. * be freed with SDL_free() when it is no longer needed.
  433. *
  434. * \since This function is available since SDL 3.1.3.
  435. *
  436. * \sa SDL_AddGamepadMapping
  437. * \sa SDL_GetGamepadMappingForID
  438. * \sa SDL_GetGamepadMappingForGUID
  439. * \sa SDL_SetGamepadMapping
  440. */
  441. extern SDL_DECLSPEC char * SDLCALL SDL_GetGamepadMapping(SDL_Gamepad *gamepad);
  442. /**
  443. * Set the current mapping of a joystick or gamepad.
  444. *
  445. * Details about mappings are discussed with SDL_AddGamepadMapping().
  446. *
  447. * \param instance_id the joystick instance ID.
  448. * \param mapping the mapping to use for this device, or NULL to clear the
  449. * mapping.
  450. * \returns true on success or false on failure; call SDL_GetError() for more
  451. * information.
  452. *
  453. * \since This function is available since SDL 3.1.3.
  454. *
  455. * \sa SDL_AddGamepadMapping
  456. * \sa SDL_GetGamepadMapping
  457. */
  458. extern SDL_DECLSPEC bool SDLCALL SDL_SetGamepadMapping(SDL_JoystickID instance_id, const char *mapping);
  459. /**
  460. * Return whether a gamepad is currently connected.
  461. *
  462. * \returns true if a gamepad is connected, false otherwise.
  463. *
  464. * \since This function is available since SDL 3.1.3.
  465. *
  466. * \sa SDL_GetGamepads
  467. */
  468. extern SDL_DECLSPEC bool SDLCALL SDL_HasGamepad(void);
  469. /**
  470. * Get a list of currently connected gamepads.
  471. *
  472. * \param count a pointer filled in with the number of gamepads returned, may
  473. * be NULL.
  474. * \returns a 0 terminated array of joystick instance IDs or NULL on failure;
  475. * call SDL_GetError() for more information. This should be freed
  476. * with SDL_free() when it is no longer needed.
  477. *
  478. * \since This function is available since SDL 3.1.3.
  479. *
  480. * \sa SDL_HasGamepad
  481. * \sa SDL_OpenGamepad
  482. */
  483. extern SDL_DECLSPEC SDL_JoystickID * SDLCALL SDL_GetGamepads(int *count);
  484. /**
  485. * Check if the given joystick is supported by the gamepad interface.
  486. *
  487. * \param instance_id the joystick instance ID.
  488. * \returns true if the given joystick is supported by the gamepad interface,
  489. * false if it isn't or it's an invalid index.
  490. *
  491. * \since This function is available since SDL 3.1.3.
  492. *
  493. * \sa SDL_GetJoysticks
  494. * \sa SDL_OpenGamepad
  495. */
  496. extern SDL_DECLSPEC bool SDLCALL SDL_IsGamepad(SDL_JoystickID instance_id);
  497. /**
  498. * Get the implementation dependent name of a gamepad.
  499. *
  500. * This can be called before any gamepads are opened.
  501. *
  502. * \param instance_id the joystick instance ID.
  503. * \returns the name of the selected gamepad. If no name can be found, this
  504. * function returns NULL; call SDL_GetError() for more information.
  505. *
  506. * \since This function is available since SDL 3.1.3.
  507. *
  508. * \sa SDL_GetGamepadName
  509. * \sa SDL_GetGamepads
  510. */
  511. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadNameForID(SDL_JoystickID instance_id);
  512. /**
  513. * Get the implementation dependent path of a gamepad.
  514. *
  515. * This can be called before any gamepads are opened.
  516. *
  517. * \param instance_id the joystick instance ID.
  518. * \returns the path of the selected gamepad. If no path can be found, this
  519. * function returns NULL; call SDL_GetError() for more information.
  520. *
  521. * \since This function is available since SDL 3.1.3.
  522. *
  523. * \sa SDL_GetGamepadPath
  524. * \sa SDL_GetGamepads
  525. */
  526. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadPathForID(SDL_JoystickID instance_id);
  527. /**
  528. * Get the player index of a gamepad.
  529. *
  530. * This can be called before any gamepads are opened.
  531. *
  532. * \param instance_id the joystick instance ID.
  533. * \returns the player index of a gamepad, or -1 if it's not available.
  534. *
  535. * \since This function is available since SDL 3.1.3.
  536. *
  537. * \sa SDL_GetGamepadPlayerIndex
  538. * \sa SDL_GetGamepads
  539. */
  540. extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadPlayerIndexForID(SDL_JoystickID instance_id);
  541. /**
  542. * Get the implementation-dependent GUID of a gamepad.
  543. *
  544. * This can be called before any gamepads are opened.
  545. *
  546. * \param instance_id the joystick instance ID.
  547. * \returns the GUID of the selected gamepad. If called on an invalid index,
  548. * this function returns a zero GUID.
  549. *
  550. * \since This function is available since SDL 3.1.3.
  551. *
  552. * \sa SDL_GUIDToString
  553. * \sa SDL_GetGamepads
  554. */
  555. extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GetGamepadGUIDForID(SDL_JoystickID instance_id);
  556. /**
  557. * Get the USB vendor ID of a gamepad, if available.
  558. *
  559. * This can be called before any gamepads are opened. If the vendor ID isn't
  560. * available this function returns 0.
  561. *
  562. * \param instance_id the joystick instance ID.
  563. * \returns the USB vendor ID of the selected gamepad. If called on an invalid
  564. * index, this function returns zero.
  565. *
  566. * \since This function is available since SDL 3.1.3.
  567. *
  568. * \sa SDL_GetGamepadVendor
  569. * \sa SDL_GetGamepads
  570. */
  571. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadVendorForID(SDL_JoystickID instance_id);
  572. /**
  573. * Get the USB product ID of a gamepad, if available.
  574. *
  575. * This can be called before any gamepads are opened. If the product ID isn't
  576. * available this function returns 0.
  577. *
  578. * \param instance_id the joystick instance ID.
  579. * \returns the USB product ID of the selected gamepad. If called on an
  580. * invalid index, this function returns zero.
  581. *
  582. * \since This function is available since SDL 3.1.3.
  583. *
  584. * \sa SDL_GetGamepadProduct
  585. * \sa SDL_GetGamepads
  586. */
  587. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductForID(SDL_JoystickID instance_id);
  588. /**
  589. * Get the product version of a gamepad, if available.
  590. *
  591. * This can be called before any gamepads are opened. If the product version
  592. * isn't available this function returns 0.
  593. *
  594. * \param instance_id the joystick instance ID.
  595. * \returns the product version of the selected gamepad. If called on an
  596. * invalid index, this function returns zero.
  597. *
  598. * \since This function is available since SDL 3.1.3.
  599. *
  600. * \sa SDL_GetGamepadProductVersion
  601. * \sa SDL_GetGamepads
  602. */
  603. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductVersionForID(SDL_JoystickID instance_id);
  604. /**
  605. * Get the type of a gamepad.
  606. *
  607. * This can be called before any gamepads are opened.
  608. *
  609. * \param instance_id the joystick instance ID.
  610. * \returns the gamepad type.
  611. *
  612. * \since This function is available since SDL 3.1.3.
  613. *
  614. * \sa SDL_GetGamepadType
  615. * \sa SDL_GetGamepads
  616. * \sa SDL_GetRealGamepadTypeForID
  617. */
  618. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadTypeForID(SDL_JoystickID instance_id);
  619. /**
  620. * Get the type of a gamepad, ignoring any mapping override.
  621. *
  622. * This can be called before any gamepads are opened.
  623. *
  624. * \param instance_id the joystick instance ID.
  625. * \returns the gamepad type.
  626. *
  627. * \since This function is available since SDL 3.1.3.
  628. *
  629. * \sa SDL_GetGamepadTypeForID
  630. * \sa SDL_GetGamepads
  631. * \sa SDL_GetRealGamepadType
  632. */
  633. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetRealGamepadTypeForID(SDL_JoystickID instance_id);
  634. /**
  635. * Get the mapping of a gamepad.
  636. *
  637. * This can be called before any gamepads are opened.
  638. *
  639. * \param instance_id the joystick instance ID.
  640. * \returns the mapping string. Returns NULL if no mapping is available. This
  641. * should be freed with SDL_free() when it is no longer needed.
  642. *
  643. * \since This function is available since SDL 3.1.3.
  644. *
  645. * \sa SDL_GetGamepads
  646. * \sa SDL_GetGamepadMapping
  647. */
  648. extern SDL_DECLSPEC char * SDLCALL SDL_GetGamepadMappingForID(SDL_JoystickID instance_id);
  649. /**
  650. * Open a gamepad for use.
  651. *
  652. * \param instance_id the joystick instance ID.
  653. * \returns a gamepad identifier or NULL if an error occurred; call
  654. * SDL_GetError() for more information.
  655. *
  656. * \since This function is available since SDL 3.1.3.
  657. *
  658. * \sa SDL_CloseGamepad
  659. * \sa SDL_IsGamepad
  660. */
  661. extern SDL_DECLSPEC SDL_Gamepad * SDLCALL SDL_OpenGamepad(SDL_JoystickID instance_id);
  662. /**
  663. * Get the SDL_Gamepad associated with a joystick instance ID, if it has been
  664. * opened.
  665. *
  666. * \param instance_id the joystick instance ID of the gamepad.
  667. * \returns an SDL_Gamepad on success or NULL on failure or if it hasn't been
  668. * opened yet; call SDL_GetError() for more information.
  669. *
  670. * \since This function is available since SDL 3.1.3.
  671. */
  672. extern SDL_DECLSPEC SDL_Gamepad * SDLCALL SDL_GetGamepadFromID(SDL_JoystickID instance_id);
  673. /**
  674. * Get the SDL_Gamepad associated with a player index.
  675. *
  676. * \param player_index the player index, which different from the instance ID.
  677. * \returns the SDL_Gamepad associated with a player index.
  678. *
  679. * \since This function is available since SDL 3.1.3.
  680. *
  681. * \sa SDL_GetGamepadPlayerIndex
  682. * \sa SDL_SetGamepadPlayerIndex
  683. */
  684. extern SDL_DECLSPEC SDL_Gamepad * SDLCALL SDL_GetGamepadFromPlayerIndex(int player_index);
  685. /**
  686. * Get the properties associated with an opened gamepad.
  687. *
  688. * These properties are shared with the underlying joystick object.
  689. *
  690. * The following read-only properties are provided by SDL:
  691. *
  692. * - `SDL_PROP_GAMEPAD_CAP_MONO_LED_BOOLEAN`: true if this gamepad has an LED
  693. * that has adjustable brightness
  694. * - `SDL_PROP_GAMEPAD_CAP_RGB_LED_BOOLEAN`: true if this gamepad has an LED
  695. * that has adjustable color
  696. * - `SDL_PROP_GAMEPAD_CAP_PLAYER_LED_BOOLEAN`: true if this gamepad has a
  697. * player LED
  698. * - `SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN`: true if this gamepad has
  699. * left/right rumble
  700. * - `SDL_PROP_GAMEPAD_CAP_TRIGGER_RUMBLE_BOOLEAN`: true if this gamepad has
  701. * simple trigger rumble
  702. *
  703. * \param gamepad a gamepad identifier previously returned by
  704. * SDL_OpenGamepad().
  705. * \returns a valid property ID on success or 0 on failure; call
  706. * SDL_GetError() for more information.
  707. *
  708. * \since This function is available since SDL 3.1.3.
  709. */
  710. extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetGamepadProperties(SDL_Gamepad *gamepad);
  711. #define SDL_PROP_GAMEPAD_CAP_MONO_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN
  712. #define SDL_PROP_GAMEPAD_CAP_RGB_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN
  713. #define SDL_PROP_GAMEPAD_CAP_PLAYER_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN
  714. #define SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN
  715. #define SDL_PROP_GAMEPAD_CAP_TRIGGER_RUMBLE_BOOLEAN SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN
  716. /**
  717. * Get the instance ID of an opened gamepad.
  718. *
  719. * \param gamepad a gamepad identifier previously returned by
  720. * SDL_OpenGamepad().
  721. * \returns the instance ID of the specified gamepad on success or 0 on
  722. * failure; call SDL_GetError() for more information.
  723. *
  724. * \since This function is available since SDL 3.1.3.
  725. */
  726. extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_GetGamepadID(SDL_Gamepad *gamepad);
  727. /**
  728. * Get the implementation-dependent name for an opened gamepad.
  729. *
  730. * \param gamepad a gamepad identifier previously returned by
  731. * SDL_OpenGamepad().
  732. * \returns the implementation dependent name for the gamepad, or NULL if
  733. * there is no name or the identifier passed is invalid.
  734. *
  735. * \since This function is available since SDL 3.1.3.
  736. *
  737. * \sa SDL_GetGamepadNameForID
  738. */
  739. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadName(SDL_Gamepad *gamepad);
  740. /**
  741. * Get the implementation-dependent path for an opened gamepad.
  742. *
  743. * \param gamepad a gamepad identifier previously returned by
  744. * SDL_OpenGamepad().
  745. * \returns the implementation dependent path for the gamepad, or NULL if
  746. * there is no path or the identifier passed is invalid.
  747. *
  748. * \since This function is available since SDL 3.1.3.
  749. *
  750. * \sa SDL_GetGamepadPathForID
  751. */
  752. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadPath(SDL_Gamepad *gamepad);
  753. /**
  754. * Get the type of an opened gamepad.
  755. *
  756. * \param gamepad the gamepad object to query.
  757. * \returns the gamepad type, or SDL_GAMEPAD_TYPE_UNKNOWN if it's not
  758. * available.
  759. *
  760. * \since This function is available since SDL 3.1.3.
  761. *
  762. * \sa SDL_GetGamepadTypeForID
  763. */
  764. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadType(SDL_Gamepad *gamepad);
  765. /**
  766. * Get the type of an opened gamepad, ignoring any mapping override.
  767. *
  768. * \param gamepad the gamepad object to query.
  769. * \returns the gamepad type, or SDL_GAMEPAD_TYPE_UNKNOWN if it's not
  770. * available.
  771. *
  772. * \since This function is available since SDL 3.1.3.
  773. *
  774. * \sa SDL_GetRealGamepadTypeForID
  775. */
  776. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetRealGamepadType(SDL_Gamepad *gamepad);
  777. /**
  778. * Get the player index of an opened gamepad.
  779. *
  780. * For XInput gamepads this returns the XInput user index.
  781. *
  782. * \param gamepad the gamepad object to query.
  783. * \returns the player index for gamepad, or -1 if it's not available.
  784. *
  785. * \since This function is available since SDL 3.1.3.
  786. *
  787. * \sa SDL_SetGamepadPlayerIndex
  788. */
  789. extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadPlayerIndex(SDL_Gamepad *gamepad);
  790. /**
  791. * Set the player index of an opened gamepad.
  792. *
  793. * \param gamepad the gamepad object to adjust.
  794. * \param player_index player index to assign to this gamepad, or -1 to clear
  795. * the player index and turn off player LEDs.
  796. * \returns true on success or false on failure; call SDL_GetError() for more
  797. * information.
  798. *
  799. * \since This function is available since SDL 3.1.3.
  800. *
  801. * \sa SDL_GetGamepadPlayerIndex
  802. */
  803. extern SDL_DECLSPEC bool SDLCALL SDL_SetGamepadPlayerIndex(SDL_Gamepad *gamepad, int player_index);
  804. /**
  805. * Get the USB vendor ID of an opened gamepad, if available.
  806. *
  807. * If the vendor ID isn't available this function returns 0.
  808. *
  809. * \param gamepad the gamepad object to query.
  810. * \returns the USB vendor ID, or zero if unavailable.
  811. *
  812. * \since This function is available since SDL 3.1.3.
  813. *
  814. * \sa SDL_GetGamepadVendorForID
  815. */
  816. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadVendor(SDL_Gamepad *gamepad);
  817. /**
  818. * Get the USB product ID of an opened gamepad, if available.
  819. *
  820. * If the product ID isn't available this function returns 0.
  821. *
  822. * \param gamepad the gamepad object to query.
  823. * \returns the USB product ID, or zero if unavailable.
  824. *
  825. * \since This function is available since SDL 3.1.3.
  826. *
  827. * \sa SDL_GetGamepadProductForID
  828. */
  829. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProduct(SDL_Gamepad *gamepad);
  830. /**
  831. * Get the product version of an opened gamepad, if available.
  832. *
  833. * If the product version isn't available this function returns 0.
  834. *
  835. * \param gamepad the gamepad object to query.
  836. * \returns the USB product version, or zero if unavailable.
  837. *
  838. * \since This function is available since SDL 3.1.3.
  839. *
  840. * \sa SDL_GetGamepadProductVersionForID
  841. */
  842. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductVersion(SDL_Gamepad *gamepad);
  843. /**
  844. * Get the firmware version of an opened gamepad, if available.
  845. *
  846. * If the firmware version isn't available this function returns 0.
  847. *
  848. * \param gamepad the gamepad object to query.
  849. * \returns the gamepad firmware version, or zero if unavailable.
  850. *
  851. * \since This function is available since SDL 3.1.3.
  852. */
  853. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadFirmwareVersion(SDL_Gamepad *gamepad);
  854. /**
  855. * Get the serial number of an opened gamepad, if available.
  856. *
  857. * Returns the serial number of the gamepad, or NULL if it is not available.
  858. *
  859. * \param gamepad the gamepad object to query.
  860. * \returns the serial number, or NULL if unavailable.
  861. *
  862. * \since This function is available since SDL 3.1.3.
  863. */
  864. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadSerial(SDL_Gamepad *gamepad);
  865. /**
  866. * Get the Steam Input handle of an opened gamepad, if available.
  867. *
  868. * Returns an InputHandle_t for the gamepad that can be used with Steam Input
  869. * API: https://partner.steamgames.com/doc/api/ISteamInput
  870. *
  871. * \param gamepad the gamepad object to query.
  872. * \returns the gamepad handle, or 0 if unavailable.
  873. *
  874. * \since This function is available since SDL 3.1.3.
  875. */
  876. extern SDL_DECLSPEC Uint64 SDLCALL SDL_GetGamepadSteamHandle(SDL_Gamepad *gamepad);
  877. /**
  878. * Get the connection state of a gamepad.
  879. *
  880. * \param gamepad the gamepad object to query.
  881. * \returns the connection state on success or
  882. * `SDL_JOYSTICK_CONNECTION_INVALID` on failure; call SDL_GetError()
  883. * for more information.
  884. *
  885. * \since This function is available since SDL 3.1.3.
  886. */
  887. extern SDL_DECLSPEC SDL_JoystickConnectionState SDLCALL SDL_GetGamepadConnectionState(SDL_Gamepad *gamepad);
  888. /**
  889. * Get the battery state of a gamepad.
  890. *
  891. * You should never take a battery status as absolute truth. Batteries
  892. * (especially failing batteries) are delicate hardware, and the values
  893. * reported here are best estimates based on what that hardware reports. It's
  894. * not uncommon for older batteries to lose stored power much faster than it
  895. * reports, or completely drain when reporting it has 20 percent left, etc.
  896. *
  897. * \param gamepad the gamepad object to query.
  898. * \param percent a pointer filled in with the percentage of battery life
  899. * left, between 0 and 100, or NULL to ignore. This will be
  900. * filled in with -1 we can't determine a value or there is no
  901. * battery.
  902. * \returns the current battery state.
  903. *
  904. * \since This function is available since SDL 3.1.3.
  905. */
  906. extern SDL_DECLSPEC SDL_PowerState SDLCALL SDL_GetGamepadPowerInfo(SDL_Gamepad *gamepad, int *percent);
  907. /**
  908. * Check if a gamepad has been opened and is currently connected.
  909. *
  910. * \param gamepad a gamepad identifier previously returned by
  911. * SDL_OpenGamepad().
  912. * \returns true if the gamepad has been opened and is currently connected, or
  913. * false if not.
  914. *
  915. * \since This function is available since SDL 3.1.3.
  916. */
  917. extern SDL_DECLSPEC bool SDLCALL SDL_GamepadConnected(SDL_Gamepad *gamepad);
  918. /**
  919. * Get the underlying joystick from a gamepad.
  920. *
  921. * This function will give you a SDL_Joystick object, which allows you to use
  922. * the SDL_Joystick functions with a SDL_Gamepad object. This would be useful
  923. * for getting a joystick's position at any given time, even if it hasn't
  924. * moved (moving it would produce an event, which would have the axis' value).
  925. *
  926. * The pointer returned is owned by the SDL_Gamepad. You should not call
  927. * SDL_CloseJoystick() on it, for example, since doing so will likely cause
  928. * SDL to crash.
  929. *
  930. * \param gamepad the gamepad object that you want to get a joystick from.
  931. * \returns an SDL_Joystick object, or NULL on failure; call SDL_GetError()
  932. * for more information.
  933. *
  934. * \since This function is available since SDL 3.1.3.
  935. */
  936. extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetGamepadJoystick(SDL_Gamepad *gamepad);
  937. /**
  938. * Set the state of gamepad event processing.
  939. *
  940. * If gamepad events are disabled, you must call SDL_UpdateGamepads() yourself
  941. * and check the state of the gamepad when you want gamepad information.
  942. *
  943. * \param enabled whether to process gamepad events or not.
  944. *
  945. * \since This function is available since SDL 3.1.3.
  946. *
  947. * \sa SDL_GamepadEventsEnabled
  948. * \sa SDL_UpdateGamepads
  949. */
  950. extern SDL_DECLSPEC void SDLCALL SDL_SetGamepadEventsEnabled(bool enabled);
  951. /**
  952. * Query the state of gamepad event processing.
  953. *
  954. * If gamepad events are disabled, you must call SDL_UpdateGamepads() yourself
  955. * and check the state of the gamepad when you want gamepad information.
  956. *
  957. * \returns true if gamepad events are being processed, false otherwise.
  958. *
  959. * \since This function is available since SDL 3.1.3.
  960. *
  961. * \sa SDL_SetGamepadEventsEnabled
  962. */
  963. extern SDL_DECLSPEC bool SDLCALL SDL_GamepadEventsEnabled(void);
  964. /**
  965. * Get the SDL joystick layer bindings for a gamepad.
  966. *
  967. * \param gamepad a gamepad.
  968. * \param count a pointer filled in with the number of bindings returned.
  969. * \returns a NULL terminated array of pointers to bindings or NULL on
  970. * failure; call SDL_GetError() for more information. This is a
  971. * single allocation that should be freed with SDL_free() when it is
  972. * no longer needed.
  973. *
  974. * \since This function is available since SDL 3.1.3.
  975. */
  976. extern SDL_DECLSPEC SDL_GamepadBinding ** SDLCALL SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count);
  977. /**
  978. * Manually pump gamepad updates if not using the loop.
  979. *
  980. * This function is called automatically by the event loop if events are
  981. * enabled. Under such circumstances, it will not be necessary to call this
  982. * function.
  983. *
  984. * \since This function is available since SDL 3.1.3.
  985. */
  986. extern SDL_DECLSPEC void SDLCALL SDL_UpdateGamepads(void);
  987. /**
  988. * Convert a string into SDL_GamepadType enum.
  989. *
  990. * This function is called internally to translate SDL_Gamepad mapping strings
  991. * for the underlying joystick device into the consistent SDL_Gamepad mapping.
  992. * You do not normally need to call this function unless you are parsing
  993. * SDL_Gamepad mappings in your own code.
  994. *
  995. * \param str string representing a SDL_GamepadType type.
  996. * \returns the SDL_GamepadType enum corresponding to the input string, or
  997. * `SDL_GAMEPAD_TYPE_UNKNOWN` if no match was found.
  998. *
  999. * \since This function is available since SDL 3.1.3.
  1000. *
  1001. * \sa SDL_GetGamepadStringForType
  1002. */
  1003. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadTypeFromString(const char *str);
  1004. /**
  1005. * Convert from an SDL_GamepadType enum to a string.
  1006. *
  1007. * \param type an enum value for a given SDL_GamepadType.
  1008. * \returns a string for the given type, or NULL if an invalid type is
  1009. * specified. The string returned is of the format used by
  1010. * SDL_Gamepad mapping strings.
  1011. *
  1012. * \since This function is available since SDL 3.1.3.
  1013. *
  1014. * \sa SDL_GetGamepadTypeFromString
  1015. */
  1016. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForType(SDL_GamepadType type);
  1017. /**
  1018. * Convert a string into SDL_GamepadAxis enum.
  1019. *
  1020. * This function is called internally to translate SDL_Gamepad mapping strings
  1021. * for the underlying joystick device into the consistent SDL_Gamepad mapping.
  1022. * You do not normally need to call this function unless you are parsing
  1023. * SDL_Gamepad mappings in your own code.
  1024. *
  1025. * Note specially that "righttrigger" and "lefttrigger" map to
  1026. * `SDL_GAMEPAD_AXIS_RIGHT_TRIGGER` and `SDL_GAMEPAD_AXIS_LEFT_TRIGGER`,
  1027. * respectively.
  1028. *
  1029. * \param str string representing a SDL_Gamepad axis.
  1030. * \returns the SDL_GamepadAxis enum corresponding to the input string, or
  1031. * `SDL_GAMEPAD_AXIS_INVALID` if no match was found.
  1032. *
  1033. * \since This function is available since SDL 3.1.3.
  1034. *
  1035. * \sa SDL_GetGamepadStringForAxis
  1036. */
  1037. extern SDL_DECLSPEC SDL_GamepadAxis SDLCALL SDL_GetGamepadAxisFromString(const char *str);
  1038. /**
  1039. * Convert from an SDL_GamepadAxis enum to a string.
  1040. *
  1041. * \param axis an enum value for a given SDL_GamepadAxis.
  1042. * \returns a string for the given axis, or NULL if an invalid axis is
  1043. * specified. The string returned is of the format used by
  1044. * SDL_Gamepad mapping strings.
  1045. *
  1046. * \since This function is available since SDL 3.1.3.
  1047. *
  1048. * \sa SDL_GetGamepadAxisFromString
  1049. */
  1050. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForAxis(SDL_GamepadAxis axis);
  1051. /**
  1052. * Query whether a gamepad has a given axis.
  1053. *
  1054. * This merely reports whether the gamepad's mapping defined this axis, as
  1055. * that is all the information SDL has about the physical device.
  1056. *
  1057. * \param gamepad a gamepad.
  1058. * \param axis an axis enum value (an SDL_GamepadAxis value).
  1059. * \returns true if the gamepad has this axis, false otherwise.
  1060. *
  1061. * \since This function is available since SDL 3.1.3.
  1062. *
  1063. * \sa SDL_GamepadHasButton
  1064. * \sa SDL_GetGamepadAxis
  1065. */
  1066. extern SDL_DECLSPEC bool SDLCALL SDL_GamepadHasAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  1067. /**
  1068. * Get the current state of an axis control on a gamepad.
  1069. *
  1070. * The axis indices start at index 0.
  1071. *
  1072. * For thumbsticks, the state is a value ranging from -32768 (up/left) to
  1073. * 32767 (down/right).
  1074. *
  1075. * Triggers range from 0 when released to 32767 when fully pressed, and never
  1076. * return a negative value. Note that this differs from the value reported by
  1077. * the lower-level SDL_GetJoystickAxis(), which normally uses the full range.
  1078. *
  1079. * \param gamepad a gamepad.
  1080. * \param axis an axis index (one of the SDL_GamepadAxis values).
  1081. * \returns axis state (including 0) on success or 0 (also) on failure; call
  1082. * SDL_GetError() for more information.
  1083. *
  1084. * \since This function is available since SDL 3.1.3.
  1085. *
  1086. * \sa SDL_GamepadHasAxis
  1087. * \sa SDL_GetGamepadButton
  1088. */
  1089. extern SDL_DECLSPEC Sint16 SDLCALL SDL_GetGamepadAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  1090. /**
  1091. * Convert a string into an SDL_GamepadButton enum.
  1092. *
  1093. * This function is called internally to translate SDL_Gamepad mapping strings
  1094. * for the underlying joystick device into the consistent SDL_Gamepad mapping.
  1095. * You do not normally need to call this function unless you are parsing
  1096. * SDL_Gamepad mappings in your own code.
  1097. *
  1098. * \param str string representing a SDL_Gamepad axis.
  1099. * \returns the SDL_GamepadButton enum corresponding to the input string, or
  1100. * `SDL_GAMEPAD_BUTTON_INVALID` if no match was found.
  1101. *
  1102. * \since This function is available since SDL 3.1.3.
  1103. *
  1104. * \sa SDL_GetGamepadStringForButton
  1105. */
  1106. extern SDL_DECLSPEC SDL_GamepadButton SDLCALL SDL_GetGamepadButtonFromString(const char *str);
  1107. /**
  1108. * Convert from an SDL_GamepadButton enum to a string.
  1109. *
  1110. * \param button an enum value for a given SDL_GamepadButton.
  1111. * \returns a string for the given button, or NULL if an invalid button is
  1112. * specified. The string returned is of the format used by
  1113. * SDL_Gamepad mapping strings.
  1114. *
  1115. * \since This function is available since SDL 3.1.3.
  1116. *
  1117. * \sa SDL_GetGamepadButtonFromString
  1118. */
  1119. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForButton(SDL_GamepadButton button);
  1120. /**
  1121. * Query whether a gamepad has a given button.
  1122. *
  1123. * This merely reports whether the gamepad's mapping defined this button, as
  1124. * that is all the information SDL has about the physical device.
  1125. *
  1126. * \param gamepad a gamepad.
  1127. * \param button a button enum value (an SDL_GamepadButton value).
  1128. * \returns true if the gamepad has this button, false otherwise.
  1129. *
  1130. * \since This function is available since SDL 3.1.3.
  1131. *
  1132. * \sa SDL_GamepadHasAxis
  1133. */
  1134. extern SDL_DECLSPEC bool SDLCALL SDL_GamepadHasButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  1135. /**
  1136. * Get the current state of a button on a gamepad.
  1137. *
  1138. * \param gamepad a gamepad.
  1139. * \param button a button index (one of the SDL_GamepadButton values).
  1140. * \returns true if the button is pressed, false otherwise.
  1141. *
  1142. * \since This function is available since SDL 3.1.3.
  1143. *
  1144. * \sa SDL_GamepadHasButton
  1145. * \sa SDL_GetGamepadAxis
  1146. */
  1147. extern SDL_DECLSPEC bool SDLCALL SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  1148. /**
  1149. * Get the label of a button on a gamepad.
  1150. *
  1151. * \param type the type of gamepad to check.
  1152. * \param button a button index (one of the SDL_GamepadButton values).
  1153. * \returns the SDL_GamepadButtonLabel enum corresponding to the button label.
  1154. *
  1155. * \since This function is available since SDL 3.1.3.
  1156. *
  1157. * \sa SDL_GetGamepadButtonLabel
  1158. */
  1159. extern SDL_DECLSPEC SDL_GamepadButtonLabel SDLCALL SDL_GetGamepadButtonLabelForType(SDL_GamepadType type, SDL_GamepadButton button);
  1160. /**
  1161. * Get the label of a button on a gamepad.
  1162. *
  1163. * \param gamepad a gamepad.
  1164. * \param button a button index (one of the SDL_GamepadButton values).
  1165. * \returns the SDL_GamepadButtonLabel enum corresponding to the button label.
  1166. *
  1167. * \since This function is available since SDL 3.1.3.
  1168. *
  1169. * \sa SDL_GetGamepadButtonLabelForType
  1170. */
  1171. extern SDL_DECLSPEC SDL_GamepadButtonLabel SDLCALL SDL_GetGamepadButtonLabel(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  1172. /**
  1173. * Get the number of touchpads on a gamepad.
  1174. *
  1175. * \param gamepad a gamepad.
  1176. * \returns number of touchpads.
  1177. *
  1178. * \since This function is available since SDL 3.1.3.
  1179. *
  1180. * \sa SDL_GetNumGamepadTouchpadFingers
  1181. */
  1182. extern SDL_DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpads(SDL_Gamepad *gamepad);
  1183. /**
  1184. * Get the number of supported simultaneous fingers on a touchpad on a game
  1185. * gamepad.
  1186. *
  1187. * \param gamepad a gamepad.
  1188. * \param touchpad a touchpad.
  1189. * \returns number of supported simultaneous fingers.
  1190. *
  1191. * \since This function is available since SDL 3.1.3.
  1192. *
  1193. * \sa SDL_GetGamepadTouchpadFinger
  1194. * \sa SDL_GetNumGamepadTouchpads
  1195. */
  1196. extern SDL_DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpadFingers(SDL_Gamepad *gamepad, int touchpad);
  1197. /**
  1198. * Get the current state of a finger on a touchpad on a gamepad.
  1199. *
  1200. * \param gamepad a gamepad.
  1201. * \param touchpad a touchpad.
  1202. * \param finger a finger.
  1203. * \param down a pointer filled with true if the finger is down, false
  1204. * otherwise, may be NULL.
  1205. * \param x a pointer filled with the x position, normalized 0 to 1, with the
  1206. * origin in the upper left, may be NULL.
  1207. * \param y a pointer filled with the y position, normalized 0 to 1, with the
  1208. * origin in the upper left, may be NULL.
  1209. * \param pressure a pointer filled with pressure value, may be NULL.
  1210. * \returns true on success or false on failure; call SDL_GetError() for more
  1211. * information.
  1212. *
  1213. * \since This function is available since SDL 3.1.3.
  1214. *
  1215. * \sa SDL_GetNumGamepadTouchpadFingers
  1216. */
  1217. extern SDL_DECLSPEC bool SDLCALL SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, bool *down, float *x, float *y, float *pressure);
  1218. /**
  1219. * Return whether a gamepad has a particular sensor.
  1220. *
  1221. * \param gamepad the gamepad to query.
  1222. * \param type the type of sensor to query.
  1223. * \returns true if the sensor exists, false otherwise.
  1224. *
  1225. * \since This function is available since SDL 3.1.3.
  1226. *
  1227. * \sa SDL_GetGamepadSensorData
  1228. * \sa SDL_GetGamepadSensorDataRate
  1229. * \sa SDL_SetGamepadSensorEnabled
  1230. */
  1231. extern SDL_DECLSPEC bool SDLCALL SDL_GamepadHasSensor(SDL_Gamepad *gamepad, SDL_SensorType type);
  1232. /**
  1233. * Set whether data reporting for a gamepad sensor is enabled.
  1234. *
  1235. * \param gamepad the gamepad to update.
  1236. * \param type the type of sensor to enable/disable.
  1237. * \param enabled whether data reporting should be enabled.
  1238. * \returns true on success or false on failure; call SDL_GetError() for more
  1239. * information.
  1240. *
  1241. * \since This function is available since SDL 3.1.3.
  1242. *
  1243. * \sa SDL_GamepadHasSensor
  1244. * \sa SDL_GamepadSensorEnabled
  1245. */
  1246. extern SDL_DECLSPEC bool SDLCALL SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, bool enabled);
  1247. /**
  1248. * Query whether sensor data reporting is enabled for a gamepad.
  1249. *
  1250. * \param gamepad the gamepad to query.
  1251. * \param type the type of sensor to query.
  1252. * \returns true if the sensor is enabled, false otherwise.
  1253. *
  1254. * \since This function is available since SDL 3.1.3.
  1255. *
  1256. * \sa SDL_SetGamepadSensorEnabled
  1257. */
  1258. extern SDL_DECLSPEC bool SDLCALL SDL_GamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type);
  1259. /**
  1260. * Get the data rate (number of events per second) of a gamepad sensor.
  1261. *
  1262. * \param gamepad the gamepad to query.
  1263. * \param type the type of sensor to query.
  1264. * \returns the data rate, or 0.0f if the data rate is not available.
  1265. *
  1266. * \since This function is available since SDL 3.1.3.
  1267. */
  1268. extern SDL_DECLSPEC float SDLCALL SDL_GetGamepadSensorDataRate(SDL_Gamepad *gamepad, SDL_SensorType type);
  1269. /**
  1270. * Get the current state of a gamepad sensor.
  1271. *
  1272. * The number of values and interpretation of the data is sensor dependent.
  1273. * See SDL_sensor.h for the details for each type of sensor.
  1274. *
  1275. * \param gamepad the gamepad to query.
  1276. * \param type the type of sensor to query.
  1277. * \param data a pointer filled with the current sensor state.
  1278. * \param num_values the number of values to write to data.
  1279. * \returns true on success or false on failure; call SDL_GetError() for more
  1280. * information.
  1281. *
  1282. * \since This function is available since SDL 3.1.3.
  1283. */
  1284. extern SDL_DECLSPEC bool SDLCALL SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, SDL_SensorType type, float *data, int num_values);
  1285. /**
  1286. * Start a rumble effect on a gamepad.
  1287. *
  1288. * Each call to this function cancels any previous rumble effect, and calling
  1289. * it with 0 intensity stops any rumbling.
  1290. *
  1291. * This function requires you to process SDL events or call
  1292. * SDL_UpdateJoysticks() to update rumble state.
  1293. *
  1294. * \param gamepad the gamepad to vibrate.
  1295. * \param low_frequency_rumble the intensity of the low frequency (left)
  1296. * rumble motor, from 0 to 0xFFFF.
  1297. * \param high_frequency_rumble the intensity of the high frequency (right)
  1298. * rumble motor, from 0 to 0xFFFF.
  1299. * \param duration_ms the duration of the rumble effect, in milliseconds.
  1300. * \returns true on success or false on failure; call SDL_GetError() for more
  1301. * information.
  1302. *
  1303. * \since This function is available since SDL 3.1.3.
  1304. */
  1305. extern SDL_DECLSPEC bool SDLCALL SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
  1306. /**
  1307. * Start a rumble effect in the gamepad's triggers.
  1308. *
  1309. * Each call to this function cancels any previous trigger rumble effect, and
  1310. * calling it with 0 intensity stops any rumbling.
  1311. *
  1312. * Note that this is rumbling of the _triggers_ and not the gamepad as a
  1313. * whole. This is currently only supported on Xbox One gamepads. If you want
  1314. * the (more common) whole-gamepad rumble, use SDL_RumbleGamepad() instead.
  1315. *
  1316. * This function requires you to process SDL events or call
  1317. * SDL_UpdateJoysticks() to update rumble state.
  1318. *
  1319. * \param gamepad the gamepad to vibrate.
  1320. * \param left_rumble the intensity of the left trigger rumble motor, from 0
  1321. * to 0xFFFF.
  1322. * \param right_rumble the intensity of the right trigger rumble motor, from 0
  1323. * to 0xFFFF.
  1324. * \param duration_ms the duration of the rumble effect, in milliseconds.
  1325. * \returns true on success or false on failure; call SDL_GetError() for more
  1326. * information.
  1327. *
  1328. * \since This function is available since SDL 3.1.3.
  1329. *
  1330. * \sa SDL_RumbleGamepad
  1331. */
  1332. extern SDL_DECLSPEC bool SDLCALL SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
  1333. /**
  1334. * Update a gamepad's LED color.
  1335. *
  1336. * An example of a joystick LED is the light on the back of a PlayStation 4's
  1337. * DualShock 4 controller.
  1338. *
  1339. * For gamepads with a single color LED, the maximum of the RGB values will be
  1340. * used as the LED brightness.
  1341. *
  1342. * \param gamepad the gamepad to update.
  1343. * \param red the intensity of the red LED.
  1344. * \param green the intensity of the green LED.
  1345. * \param blue the intensity of the blue LED.
  1346. * \returns true on success or false on failure; call SDL_GetError() for more
  1347. * information.
  1348. *
  1349. * \since This function is available since SDL 3.1.3.
  1350. */
  1351. extern SDL_DECLSPEC bool SDLCALL SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue);
  1352. /**
  1353. * Send a gamepad specific effect packet.
  1354. *
  1355. * \param gamepad the gamepad to affect.
  1356. * \param data the data to send to the gamepad.
  1357. * \param size the size of the data to send to the gamepad.
  1358. * \returns true on success or false on failure; call SDL_GetError() for more
  1359. * information.
  1360. *
  1361. * \since This function is available since SDL 3.1.3.
  1362. */
  1363. extern SDL_DECLSPEC bool SDLCALL SDL_SendGamepadEffect(SDL_Gamepad *gamepad, const void *data, int size);
  1364. /**
  1365. * Close a gamepad previously opened with SDL_OpenGamepad().
  1366. *
  1367. * \param gamepad a gamepad identifier previously returned by
  1368. * SDL_OpenGamepad().
  1369. *
  1370. * \since This function is available since SDL 3.1.3.
  1371. *
  1372. * \sa SDL_OpenGamepad
  1373. */
  1374. extern SDL_DECLSPEC void SDLCALL SDL_CloseGamepad(SDL_Gamepad *gamepad);
  1375. /**
  1376. * Return the sfSymbolsName for a given button on a gamepad on Apple
  1377. * platforms.
  1378. *
  1379. * \param gamepad the gamepad to query.
  1380. * \param button a button on the gamepad.
  1381. * \returns the sfSymbolsName or NULL if the name can't be found.
  1382. *
  1383. * \since This function is available since SDL 3.1.3.
  1384. *
  1385. * \sa SDL_GetGamepadAppleSFSymbolsNameForAxis
  1386. */
  1387. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  1388. /**
  1389. * Return the sfSymbolsName for a given axis on a gamepad on Apple platforms.
  1390. *
  1391. * \param gamepad the gamepad to query.
  1392. * \param axis an axis on the gamepad.
  1393. * \returns the sfSymbolsName or NULL if the name can't be found.
  1394. *
  1395. * \since This function is available since SDL 3.1.3.
  1396. *
  1397. * \sa SDL_GetGamepadAppleSFSymbolsNameForButton
  1398. */
  1399. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  1400. /* Ends C function definitions when using C++ */
  1401. #ifdef __cplusplus
  1402. }
  1403. #endif
  1404. #include <SDL3/SDL_close_code.h>
  1405. #endif /* SDL_gamepad_h_ */