SDL_gamepad.h 51 KB

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