SDL_gamepad.h 52 KB

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