SDL_gamepad.h 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2023 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. * \file SDL_gamepad.h
  20. *
  21. * Include file for SDL gamepad event handling
  22. */
  23. #ifndef SDL_gamepad_h_
  24. #define SDL_gamepad_h_
  25. #include <SDL3/SDL_stdinc.h>
  26. #include <SDL3/SDL_error.h>
  27. #include <SDL3/SDL_rwops.h>
  28. #include <SDL3/SDL_sensor.h>
  29. #include <SDL3/SDL_joystick.h>
  30. #include <SDL3/SDL_begin_code.h>
  31. /* Set up for C function definitions, even when using C++ */
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. /**
  36. * \file SDL_gamepad.h
  37. *
  38. * In order to use these functions, SDL_Init() must have been called
  39. * with the ::SDL_INIT_GAMEPAD flag. This causes SDL to scan the system
  40. * for gamepads, and load appropriate drivers.
  41. *
  42. * If you would like to receive gamepad updates while the application
  43. * is in the background, you should set the following hint before calling
  44. * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
  45. */
  46. /**
  47. * The structure used to identify an SDL gamepad
  48. */
  49. struct SDL_Gamepad;
  50. typedef struct SDL_Gamepad SDL_Gamepad;
  51. typedef enum
  52. {
  53. SDL_GAMEPAD_TYPE_UNKNOWN = 0,
  54. SDL_GAMEPAD_TYPE_VIRTUAL,
  55. SDL_GAMEPAD_TYPE_XBOX360,
  56. SDL_GAMEPAD_TYPE_XBOXONE,
  57. SDL_GAMEPAD_TYPE_PS3,
  58. SDL_GAMEPAD_TYPE_PS4,
  59. SDL_GAMEPAD_TYPE_PS5,
  60. SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO,
  61. SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT,
  62. SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT,
  63. SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_PAIR,
  64. SDL_GAMEPAD_TYPE_AMAZON_LUNA,
  65. SDL_GAMEPAD_TYPE_GOOGLE_STADIA,
  66. SDL_GAMEPAD_TYPE_NVIDIA_SHIELD
  67. } SDL_GamepadType;
  68. /**
  69. * The list of buttons available on a gamepad
  70. */
  71. typedef enum
  72. {
  73. SDL_GAMEPAD_BUTTON_INVALID = -1,
  74. SDL_GAMEPAD_BUTTON_A,
  75. SDL_GAMEPAD_BUTTON_B,
  76. SDL_GAMEPAD_BUTTON_X,
  77. SDL_GAMEPAD_BUTTON_Y,
  78. SDL_GAMEPAD_BUTTON_BACK,
  79. SDL_GAMEPAD_BUTTON_GUIDE,
  80. SDL_GAMEPAD_BUTTON_START,
  81. SDL_GAMEPAD_BUTTON_LEFT_STICK,
  82. SDL_GAMEPAD_BUTTON_RIGHT_STICK,
  83. SDL_GAMEPAD_BUTTON_LEFT_SHOULDER,
  84. SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER,
  85. SDL_GAMEPAD_BUTTON_DPAD_UP,
  86. SDL_GAMEPAD_BUTTON_DPAD_DOWN,
  87. SDL_GAMEPAD_BUTTON_DPAD_LEFT,
  88. SDL_GAMEPAD_BUTTON_DPAD_RIGHT,
  89. SDL_GAMEPAD_BUTTON_MISC1, /* Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Amazon Luna microphone button */
  90. SDL_GAMEPAD_BUTTON_PADDLE1, /* Xbox Elite paddle P1 (upper left, facing the back) */
  91. SDL_GAMEPAD_BUTTON_PADDLE2, /* Xbox Elite paddle P3 (upper right, facing the back) */
  92. SDL_GAMEPAD_BUTTON_PADDLE3, /* Xbox Elite paddle P2 (lower left, facing the back) */
  93. SDL_GAMEPAD_BUTTON_PADDLE4, /* Xbox Elite paddle P4 (lower right, facing the back) */
  94. SDL_GAMEPAD_BUTTON_TOUCHPAD, /* PS4/PS5 touchpad button */
  95. SDL_GAMEPAD_BUTTON_MAX
  96. } SDL_GamepadButton;
  97. /**
  98. * The list of axes available on a gamepad
  99. *
  100. * Thumbstick axis values range from SDL_JOYSTICK_AXIS_MIN to SDL_JOYSTICK_AXIS_MAX,
  101. * and are centered within ~8000 of zero, though advanced UI will allow users to set
  102. * or autodetect the dead zone, which varies between gamepads.
  103. *
  104. * Trigger axis values range from 0 to SDL_JOYSTICK_AXIS_MAX.
  105. */
  106. typedef enum
  107. {
  108. SDL_GAMEPAD_AXIS_INVALID = -1,
  109. SDL_GAMEPAD_AXIS_LEFTX,
  110. SDL_GAMEPAD_AXIS_LEFTY,
  111. SDL_GAMEPAD_AXIS_RIGHTX,
  112. SDL_GAMEPAD_AXIS_RIGHTY,
  113. SDL_GAMEPAD_AXIS_LEFT_TRIGGER,
  114. SDL_GAMEPAD_AXIS_RIGHT_TRIGGER,
  115. SDL_GAMEPAD_AXIS_MAX
  116. } SDL_GamepadAxis;
  117. typedef enum
  118. {
  119. SDL_GAMEPAD_BINDTYPE_NONE = 0,
  120. SDL_GAMEPAD_BINDTYPE_BUTTON,
  121. SDL_GAMEPAD_BINDTYPE_AXIS,
  122. SDL_GAMEPAD_BINDTYPE_HAT
  123. } SDL_GamepadBindingType;
  124. /**
  125. * Get the SDL joystick layer binding for this gamepad button/axis mapping
  126. */
  127. typedef struct SDL_GamepadBinding
  128. {
  129. SDL_GamepadBindingType bindType;
  130. union
  131. {
  132. int button;
  133. int axis;
  134. struct {
  135. int hat;
  136. int hat_mask;
  137. } hat;
  138. } value;
  139. } SDL_GamepadBinding;
  140. /**
  141. * Add support for gamepads that SDL is unaware of or change the binding of an
  142. * existing gamepad.
  143. *
  144. * The mapping string has the format "GUID,name,mapping", where GUID is the
  145. * string value from SDL_GetJoystickGUIDString(), name is the human readable
  146. * string for the device and mappings are gamepad mappings to joystick
  147. * ones. Under Windows there is a reserved GUID of "xinput" that covers all
  148. * XInput devices. The mapping format for joystick is: {| |bX |a joystick
  149. * button, index X |- |hX.Y |hat X with value Y |- |aX |axis X of the joystick
  150. * |} Buttons can be used as a gamepad axes and vice versa.
  151. *
  152. * This string shows an example of a valid mapping for a gamepad:
  153. *
  154. * ```c
  155. * "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"
  156. * ```
  157. *
  158. * \param mappingString the mapping string
  159. * \returns 1 if a new mapping is added, 0 if an existing mapping is updated,
  160. * -1 on error; call SDL_GetError() for more information.
  161. *
  162. * \since This function is available since SDL 3.0.0.
  163. *
  164. * \sa SDL_GetGamepadMapping
  165. * \sa SDL_GetGamepadMappingForGUID
  166. */
  167. extern DECLSPEC int SDLCALL SDL_AddGamepadMapping(const char *mappingString);
  168. /**
  169. * Load a set of gamepad mappings from a seekable SDL data stream.
  170. *
  171. * You can call this function several times, if needed, to load different
  172. * database files.
  173. *
  174. * If a new mapping is loaded for an already known gamepad GUID, the later
  175. * version will overwrite the one currently loaded.
  176. *
  177. * Mappings not belonging to the current platform or with no platform field
  178. * specified will be ignored (i.e. mappings for Linux will be ignored in
  179. * Windows, etc).
  180. *
  181. * This function will load the text database entirely in memory before
  182. * processing it, so take this into consideration if you are in a memory
  183. * constrained environment.
  184. *
  185. * \param rw the data stream for the mappings to be added
  186. * \param freerw non-zero to close the stream after being read
  187. * \returns the number of mappings added or -1 on error; call SDL_GetError()
  188. * for more information.
  189. *
  190. * \since This function is available since SDL 3.0.0.
  191. *
  192. * \sa SDL_AddGamepadMapping
  193. * \sa SDL_AddGamepadMappingsFromFile
  194. * \sa SDL_GetGamepadMappingForGUID
  195. */
  196. extern DECLSPEC int SDLCALL SDL_AddGamepadMappingsFromRW(SDL_RWops *rw, int freerw);
  197. /**
  198. * Load a set of mappings from a file, filtered by the current SDL_GetPlatform()
  199. *
  200. * Convenience macro.
  201. */
  202. #define SDL_AddGamepadMappingsFromFile(file) SDL_AddGamepadMappingsFromRW(SDL_RWFromFile(file, "rb"), 1)
  203. /**
  204. * Get the number of mappings installed.
  205. *
  206. * \returns the number of mappings.
  207. *
  208. * \since This function is available since SDL 3.0.0.
  209. */
  210. extern DECLSPEC int SDLCALL SDL_GetNumGamepadMappings(void);
  211. /**
  212. * Get the mapping at a particular index.
  213. *
  214. * \returns the mapping string. Must be freed with SDL_free(). Returns NULL if
  215. * the index is out of range.
  216. *
  217. * \since This function is available since SDL 3.0.0.
  218. */
  219. extern DECLSPEC char * SDLCALL SDL_GetGamepadMappingForIndex(int mapping_index);
  220. /**
  221. * Get the gamepad mapping string for a given GUID.
  222. *
  223. * The returned string must be freed with SDL_free().
  224. *
  225. * \param guid a structure containing the GUID for which a mapping is desired
  226. * \returns a mapping string or NULL on error; call SDL_GetError() for more
  227. * information.
  228. *
  229. * \since This function is available since SDL 3.0.0.
  230. *
  231. * \sa SDL_GetJoystickInstanceGUID
  232. * \sa SDL_GetJoystickGUID
  233. */
  234. extern DECLSPEC char * SDLCALL SDL_GetGamepadMappingForGUID(SDL_JoystickGUID guid);
  235. /**
  236. * Get the current mapping of a gamepad.
  237. *
  238. * The returned string must be freed with SDL_free().
  239. *
  240. * Details about mappings are discussed with SDL_AddGamepadMapping().
  241. *
  242. * \param gamepad the gamepad you want to get the current
  243. * mapping for
  244. * \returns a string that has the gamepad's mapping or NULL if no mapping
  245. * is available; call SDL_GetError() for more information.
  246. *
  247. * \since This function is available since SDL 3.0.0.
  248. *
  249. * \sa SDL_AddGamepadMapping
  250. * \sa SDL_GetGamepadMappingForGUID
  251. */
  252. extern DECLSPEC char * SDLCALL SDL_GetGamepadMapping(SDL_Gamepad *gamepad);
  253. /**
  254. * Get a list of currently connected gamepads.
  255. *
  256. * \param count a pointer filled in with the number of gamepads returned
  257. * \returns a 0 terminated array of joystick instance IDs which should be freed with SDL_free(), or NULL on error; call SDL_GetError() for more details.
  258. *
  259. * \since This function is available since SDL 3.0.0.
  260. *
  261. * \sa SDL_OpenGamepad
  262. */
  263. extern DECLSPEC SDL_JoystickID *SDLCALL SDL_GetGamepads(int *count);
  264. /**
  265. * Check if the given joystick is supported by the gamepad interface.
  266. *
  267. * \param instance_id the joystick instance ID
  268. * \returns SDL_TRUE if the given joystick is supported by the gamepad
  269. * interface, SDL_FALSE if it isn't or it's an invalid index.
  270. *
  271. * \since This function is available since SDL 3.0.0.
  272. *
  273. * \sa SDL_GetGamepadNameForIndex
  274. * \sa SDL_OpenGamepad
  275. */
  276. extern DECLSPEC SDL_bool SDLCALL SDL_IsGamepad(SDL_JoystickID instance_id);
  277. /**
  278. * Get the implementation dependent name of a gamepad.
  279. *
  280. * This can be called before any gamepads are opened.
  281. *
  282. * \param instance_id the joystick instance ID
  283. * \returns the name of the selected gamepad. If no name can be found, this
  284. * function returns NULL; call SDL_GetError() for more information.
  285. *
  286. * \since This function is available since SDL 3.0.0.
  287. *
  288. * \sa SDL_GetGamepadName
  289. * \sa SDL_OpenGamepad
  290. */
  291. extern DECLSPEC const char *SDLCALL SDL_GetGamepadInstanceName(SDL_JoystickID instance_id);
  292. /**
  293. * Get the implementation dependent path of a gamepad.
  294. *
  295. * This can be called before any gamepads are opened.
  296. *
  297. * \param instance_id the joystick instance ID
  298. * \returns the path of the selected gamepad. If no path can be found, this
  299. * function returns NULL; call SDL_GetError() for more information.
  300. *
  301. * \since This function is available since SDL 3.0.0.
  302. *
  303. * \sa SDL_GetGamepadPath
  304. * \sa SDL_OpenGamepad
  305. */
  306. extern DECLSPEC const char *SDLCALL SDL_GetGamepadInstancePath(SDL_JoystickID instance_id);
  307. /**
  308. * Get the player index of a gamepad.
  309. *
  310. * This can be called before any gamepads are opened.
  311. *
  312. * \param instance_id the joystick instance ID
  313. * \returns the player index of a gamepad, or -1 if it's not available
  314. *
  315. * \since This function is available since SDL 3.0.0.
  316. *
  317. * \sa SDL_GetGamepadPlayerIndex
  318. * \sa SDL_OpenGamepad
  319. */
  320. extern DECLSPEC int SDLCALL SDL_GetGamepadInstancePlayerIndex(SDL_JoystickID instance_id);
  321. /**
  322. * Get the implementation-dependent GUID of a gamepad.
  323. *
  324. * This can be called before any gamepads are opened.
  325. *
  326. * \param instance_id the joystick instance ID
  327. * \returns the GUID of the selected gamepad. If called on an invalid index,
  328. * this function returns a zero GUID
  329. *
  330. * \since This function is available since SDL 3.0.0.
  331. *
  332. * \sa SDL_GetGamepadGUID
  333. * \sa SDL_GetGamepadGUIDString
  334. */
  335. extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_GetGamepadInstanceGUID(SDL_JoystickID instance_id);
  336. /**
  337. * Get the USB vendor ID of a gamepad, if available.
  338. *
  339. * This can be called before any gamepads are opened. If the vendor ID isn't
  340. * available this function returns 0.
  341. *
  342. * \param instance_id the joystick instance ID
  343. * \returns the USB vendor ID of the selected gamepad. If called on an
  344. * invalid index, this function returns zero
  345. *
  346. * \since This function is available since SDL 3.0.0.
  347. */
  348. extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadInstanceVendor(SDL_JoystickID instance_id);
  349. /**
  350. * Get the USB product ID of a gamepad, if available.
  351. *
  352. * This can be called before any gamepads are opened. If the product ID isn't
  353. * available this function returns 0.
  354. *
  355. * \param instance_id the joystick instance ID
  356. * \returns the USB product ID of the selected gamepad. If called on an
  357. * invalid index, this function returns zero
  358. *
  359. * \since This function is available since SDL 3.0.0.
  360. */
  361. extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadInstanceProduct(SDL_JoystickID instance_id);
  362. /**
  363. * Get the product version of a gamepad, if available.
  364. *
  365. * This can be called before any gamepads are opened. If the product version
  366. * isn't available this function returns 0.
  367. *
  368. * \param instance_id the joystick instance ID
  369. * \returns the product version of the selected gamepad. If called on an
  370. * invalid index, this function returns zero
  371. *
  372. * \since This function is available since SDL 3.0.0.
  373. */
  374. extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadInstanceProductVersion(SDL_JoystickID instance_id);
  375. /**
  376. * Get the type of a gamepad.
  377. *
  378. * This can be called before any gamepads are opened.
  379. *
  380. * \param instance_id the joystick instance ID
  381. * \returns the gamepad type.
  382. *
  383. * \since This function is available since SDL 3.0.0.
  384. */
  385. extern DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadInstanceType(SDL_JoystickID instance_id);
  386. /**
  387. * Get the mapping of a gamepad.
  388. *
  389. * This can be called before any gamepads are opened.
  390. *
  391. * \param instance_id the joystick instance ID
  392. * \returns the mapping string. Must be freed with SDL_free(). Returns NULL if
  393. * no mapping is available.
  394. *
  395. * \since This function is available since SDL 3.0.0.
  396. */
  397. extern DECLSPEC char *SDLCALL SDL_GetGamepadInstanceMapping(SDL_JoystickID instance_id);
  398. /**
  399. * Open a gamepad for use.
  400. *
  401. * \param instance_id the joystick instance ID
  402. * \returns a gamepad identifier or NULL if an error occurred; call
  403. * SDL_GetError() for more information.
  404. *
  405. * \since This function is available since SDL 3.0.0.
  406. *
  407. * \sa SDL_CloseGamepad
  408. * \sa SDL_GetGamepadNameForIndex
  409. * \sa SDL_IsGamepad
  410. */
  411. extern DECLSPEC SDL_Gamepad *SDLCALL SDL_OpenGamepad(SDL_JoystickID instance_id);
  412. /**
  413. * Get the SDL_Gamepad associated with a joystick instance ID.
  414. *
  415. * \param instance_id the joystick instance ID of the gamepad
  416. * \returns an SDL_Gamepad on success or NULL on failure; call
  417. * SDL_GetError() for more information.
  418. *
  419. * \since This function is available since SDL 3.0.0.
  420. */
  421. extern DECLSPEC SDL_Gamepad *SDLCALL SDL_GetGamepadFromInstanceID(SDL_JoystickID instance_id);
  422. /**
  423. * Get the SDL_Gamepad associated with a player index.
  424. *
  425. * \param player_index the player index, which different from the instance ID
  426. * \returns the SDL_Gamepad associated with a player index.
  427. *
  428. * \since This function is available since SDL 3.0.0.
  429. *
  430. * \sa SDL_GetGamepadPlayerIndex
  431. * \sa SDL_SetGamepadPlayerIndex
  432. */
  433. extern DECLSPEC SDL_Gamepad *SDLCALL SDL_GetGamepadFromPlayerIndex(int player_index);
  434. /**
  435. * Get the implementation-dependent name for an opened gamepad.
  436. *
  437. * This is the same name as returned by SDL_GetGamepadNameForIndex(), but
  438. * it takes a gamepad identifier instead of the (unstable) device index.
  439. *
  440. * \param gamepad a gamepad identifier previously returned by
  441. * SDL_OpenGamepad()
  442. * \returns the implementation dependent name for the gamepad, or NULL
  443. * if there is no name or the identifier passed is invalid.
  444. *
  445. * \since This function is available since SDL 3.0.0.
  446. *
  447. * \sa SDL_GetGamepadNameForIndex
  448. * \sa SDL_OpenGamepad
  449. */
  450. extern DECLSPEC const char *SDLCALL SDL_GetGamepadName(SDL_Gamepad *gamepad);
  451. /**
  452. * Get the implementation-dependent path for an opened gamepad.
  453. *
  454. * This is the same path as returned by SDL_GetGamepadNameForIndex(), but
  455. * it takes a gamepad identifier instead of the (unstable) device index.
  456. *
  457. * \param gamepad a gamepad identifier previously returned by
  458. * SDL_OpenGamepad()
  459. * \returns the implementation dependent path for the gamepad, or NULL
  460. * if there is no path or the identifier passed is invalid.
  461. *
  462. * \since This function is available since SDL 3.0.0.
  463. *
  464. * \sa SDL_GetGamepadInstancePath
  465. */
  466. extern DECLSPEC const char *SDLCALL SDL_GetGamepadPath(SDL_Gamepad *gamepad);
  467. /**
  468. * Get the type of this currently opened gamepad
  469. *
  470. * This is the same name as returned by SDL_GetGamepadInstanceType(), but
  471. * it takes a gamepad identifier instead of the (unstable) device index.
  472. *
  473. * \param gamepad the gamepad object to query.
  474. * \returns the gamepad type.
  475. *
  476. * \since This function is available since SDL 3.0.0.
  477. */
  478. extern DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadType(SDL_Gamepad *gamepad);
  479. /**
  480. * Get the player index of an opened gamepad.
  481. *
  482. * For XInput gamepads this returns the XInput user index.
  483. *
  484. * \param gamepad the gamepad object to query.
  485. * \returns the player index for gamepad, or -1 if it's not available.
  486. *
  487. * \since This function is available since SDL 3.0.0.
  488. */
  489. extern DECLSPEC int SDLCALL SDL_GetGamepadPlayerIndex(SDL_Gamepad *gamepad);
  490. /**
  491. * Set the player index of an opened gamepad.
  492. *
  493. * \param gamepad the gamepad object to adjust.
  494. * \param player_index Player index to assign to this gamepad, or -1 to
  495. * clear the player index and turn off player LEDs.
  496. *
  497. * \since This function is available since SDL 3.0.0.
  498. */
  499. extern DECLSPEC void SDLCALL SDL_SetGamepadPlayerIndex(SDL_Gamepad *gamepad, int player_index);
  500. /**
  501. * Get the USB vendor ID of an opened gamepad, if available.
  502. *
  503. * If the vendor ID isn't available this function returns 0.
  504. *
  505. * \param gamepad the gamepad object to query.
  506. * \return the USB vendor ID, or zero if unavailable.
  507. *
  508. * \since This function is available since SDL 3.0.0.
  509. */
  510. extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadVendor(SDL_Gamepad *gamepad);
  511. /**
  512. * Get the USB product ID of an opened gamepad, if available.
  513. *
  514. * If the product ID isn't available this function returns 0.
  515. *
  516. * \param gamepad the gamepad object to query.
  517. * \return the USB product ID, or zero if unavailable.
  518. *
  519. * \since This function is available since SDL 3.0.0.
  520. */
  521. extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadProduct(SDL_Gamepad *gamepad);
  522. /**
  523. * Get the product version of an opened gamepad, if available.
  524. *
  525. * If the product version isn't available this function returns 0.
  526. *
  527. * \param gamepad the gamepad object to query.
  528. * \return the USB product version, or zero if unavailable.
  529. *
  530. * \since This function is available since SDL 3.0.0.
  531. */
  532. extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductVersion(SDL_Gamepad *gamepad);
  533. /**
  534. * Get the firmware version of an opened gamepad, if available.
  535. *
  536. * If the firmware version isn't available this function returns 0.
  537. *
  538. * \param gamepad the gamepad object to query.
  539. * \return the gamepad firmware version, or zero if unavailable.
  540. *
  541. * \since This function is available since SDL 3.0.0.
  542. */
  543. extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadFirmwareVersion(SDL_Gamepad *gamepad);
  544. /**
  545. * Get the serial number of an opened gamepad, if available.
  546. *
  547. * Returns the serial number of the gamepad, or NULL if it is not
  548. * available.
  549. *
  550. * \param gamepad the gamepad object to query.
  551. * \return the serial number, or NULL if unavailable.
  552. *
  553. * \since This function is available since SDL 3.0.0.
  554. */
  555. extern DECLSPEC const char * SDLCALL SDL_GetGamepadSerial(SDL_Gamepad *gamepad);
  556. /**
  557. * Check if a gamepad has been opened and is currently connected.
  558. *
  559. * \param gamepad a gamepad identifier previously returned by
  560. * SDL_OpenGamepad()
  561. * \returns SDL_TRUE if the gamepad has been opened and is currently
  562. * connected, or SDL_FALSE if not.
  563. *
  564. * \since This function is available since SDL 3.0.0.
  565. *
  566. * \sa SDL_CloseGamepad
  567. * \sa SDL_OpenGamepad
  568. */
  569. extern DECLSPEC SDL_bool SDLCALL SDL_GamepadConnected(SDL_Gamepad *gamepad);
  570. /**
  571. * Get the underlying joystick from a gamepad
  572. *
  573. * This function will give you a SDL_Joystick object, which allows you to use
  574. * the SDL_Joystick functions with a SDL_Gamepad object. This would be
  575. * useful for getting a joystick's position at any given time, even if it
  576. * hasn't moved (moving it would produce an event, which would have the axis'
  577. * value).
  578. *
  579. * The pointer returned is owned by the SDL_Gamepad. You should not
  580. * call SDL_CloseJoystick() on it, for example, since doing so will likely
  581. * cause SDL to crash.
  582. *
  583. * \param gamepad the gamepad object that you want to get a
  584. * joystick from
  585. * \returns an SDL_Joystick object; call SDL_GetError() for more information.
  586. *
  587. * \since This function is available since SDL 3.0.0.
  588. */
  589. extern DECLSPEC SDL_Joystick *SDLCALL SDL_GetGamepadJoystick(SDL_Gamepad *gamepad);
  590. /**
  591. * Set the state of gamepad event processing.
  592. *
  593. * If gamepad events are disabled, you must call SDL_UpdateGamepads()
  594. * yourself and check the state of the gamepad when you want gamepad
  595. * information.
  596. *
  597. * \param enabled whether to process gamepad events or not
  598. *
  599. * \since This function is available since SDL 3.0.0.
  600. *
  601. * \sa SDL_GamepadEventsEnabled
  602. */
  603. extern DECLSPEC void SDLCALL SDL_SetGamepadEventsEnabled(SDL_bool enabled);
  604. /**
  605. * Query the state of gamepad event processing.
  606. *
  607. * If gamepad events are disabled, you must call SDL_UpdateGamepads()
  608. * yourself and check the state of the gamepad when you want gamepad
  609. * information.
  610. *
  611. * \returns SDL_TRUE if gamepad events are being processed, SDL_FALSE otherwise.
  612. *
  613. * \since This function is available since SDL 3.0.0.
  614. *
  615. * \sa SDL_SetGamepadEventsEnabled
  616. */
  617. extern DECLSPEC SDL_bool SDLCALL SDL_GamepadEventsEnabled(void);
  618. /**
  619. * Manually pump gamepad updates if not using the loop.
  620. *
  621. * This function is called automatically by the event loop if events are
  622. * enabled. Under such circumstances, it will not be necessary to call this
  623. * function.
  624. *
  625. * \since This function is available since SDL 3.0.0.
  626. */
  627. extern DECLSPEC void SDLCALL SDL_UpdateGamepads(void);
  628. /**
  629. * Convert a string into SDL_GamepadAxis enum.
  630. *
  631. * This function is called internally to translate SDL_Gamepad mapping
  632. * strings for the underlying joystick device into the consistent
  633. * SDL_Gamepad mapping. You do not normally need to call this function
  634. * unless you are parsing SDL_Gamepad mappings in your own code.
  635. *
  636. * Note specially that "righttrigger" and "lefttrigger" map to
  637. * `SDL_GAMEPAD_AXIS_RIGHT_TRIGGER` and `SDL_GAMEPAD_AXIS_LEFT_TRIGGER`,
  638. * respectively.
  639. *
  640. * \param str string representing a SDL_Gamepad axis
  641. * \returns the SDL_GamepadAxis enum corresponding to the input string,
  642. * or `SDL_GAMEPAD_AXIS_INVALID` if no match was found.
  643. *
  644. * \since This function is available since SDL 3.0.0.
  645. *
  646. * \sa SDL_GetGamepadStringForAxis
  647. */
  648. extern DECLSPEC SDL_GamepadAxis SDLCALL SDL_GetGamepadAxisFromString(const char *str);
  649. /**
  650. * Convert from an SDL_GamepadAxis enum to a string.
  651. *
  652. * The caller should not SDL_free() the returned string.
  653. *
  654. * \param axis an enum value for a given SDL_GamepadAxis
  655. * \returns a string for the given axis, or NULL if an invalid axis is
  656. * specified. The string returned is of the format used by
  657. * SDL_Gamepad mapping strings.
  658. *
  659. * \since This function is available since SDL 3.0.0.
  660. *
  661. * \sa SDL_GetGamepadAxisFromString
  662. */
  663. extern DECLSPEC const char* SDLCALL SDL_GetGamepadStringForAxis(SDL_GamepadAxis axis);
  664. /**
  665. * Get the SDL joystick layer binding for a gamepad axis mapping.
  666. *
  667. * \param gamepad a gamepad
  668. * \param axis an axis enum value (one of the SDL_GamepadAxis values)
  669. * \returns a SDL_GamepadBinding describing the bind. On failure
  670. * (like the given Controller axis doesn't exist on the device), its
  671. * `.bindType` will be `SDL_GAMEPAD_BINDTYPE_NONE`.
  672. *
  673. * \since This function is available since SDL 3.0.0.
  674. *
  675. * \sa SDL_GetGamepadBindForButton
  676. */
  677. extern DECLSPEC SDL_GamepadBinding SDLCALL SDL_GetGamepadBindForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  678. /**
  679. * Query whether a gamepad has a given axis.
  680. *
  681. * This merely reports whether the gamepad's mapping defined this axis, as
  682. * that is all the information SDL has about the physical device.
  683. *
  684. * \param gamepad a gamepad
  685. * \param axis an axis enum value (an SDL_GamepadAxis value)
  686. * \returns SDL_TRUE if the gamepad has this axis, SDL_FALSE otherwise.
  687. *
  688. * \since This function is available since SDL 3.0.0.
  689. */
  690. extern DECLSPEC SDL_bool SDLCALL SDL_GamepadHasAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  691. /**
  692. * Get the current state of an axis control on a gamepad.
  693. *
  694. * The axis indices start at index 0.
  695. *
  696. * The state is a value ranging from -32768 to 32767. Triggers, however, range
  697. * from 0 to 32767 (they never return a negative value).
  698. *
  699. * \param gamepad a gamepad
  700. * \param axis an axis index (one of the SDL_GamepadAxis values)
  701. * \returns axis state (including 0) on success or 0 (also) on failure; call
  702. * SDL_GetError() for more information.
  703. *
  704. * \since This function is available since SDL 3.0.0.
  705. *
  706. * \sa SDL_GetGamepadButton
  707. */
  708. extern DECLSPEC Sint16 SDLCALL SDL_GetGamepadAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  709. /**
  710. * Convert a string into an SDL_GamepadButton enum.
  711. *
  712. * This function is called internally to translate SDL_Gamepad mapping
  713. * strings for the underlying joystick device into the consistent
  714. * SDL_Gamepad mapping. You do not normally need to call this function
  715. * unless you are parsing SDL_Gamepad mappings in your own code.
  716. *
  717. * \param str string representing a SDL_Gamepad axis
  718. * \returns the SDL_GamepadButton enum corresponding to the input
  719. * string, or `SDL_GAMEPAD_AXIS_INVALID` if no match was found.
  720. *
  721. * \since This function is available since SDL 3.0.0.
  722. */
  723. extern DECLSPEC SDL_GamepadButton SDLCALL SDL_GetGamepadButtonFromString(const char *str);
  724. /**
  725. * Convert from an SDL_GamepadButton enum to a string.
  726. *
  727. * The caller should not SDL_free() the returned string.
  728. *
  729. * \param button an enum value for a given SDL_GamepadButton
  730. * \returns a string for the given button, or NULL if an invalid button is
  731. * specified. The string returned is of the format used by
  732. * SDL_Gamepad mapping strings.
  733. *
  734. * \since This function is available since SDL 3.0.0.
  735. *
  736. * \sa SDL_GetGamepadButtonFromString
  737. */
  738. extern DECLSPEC const char* SDLCALL SDL_GetGamepadStringForButton(SDL_GamepadButton button);
  739. /**
  740. * Get the SDL joystick layer binding for a gamepad button mapping.
  741. *
  742. * \param gamepad a gamepad
  743. * \param button an button enum value (an SDL_GamepadButton value)
  744. * \returns a SDL_GamepadBinding describing the bind. On failure
  745. * (like the given Controller button doesn't exist on the device),
  746. * its `.bindType` will be `SDL_GAMEPAD_BINDTYPE_NONE`.
  747. *
  748. * \since This function is available since SDL 3.0.0.
  749. *
  750. * \sa SDL_GetGamepadBindForAxis
  751. */
  752. extern DECLSPEC SDL_GamepadBinding SDLCALL SDL_GetGamepadBindForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  753. /**
  754. * Query whether a gamepad has a given button.
  755. *
  756. * This merely reports whether the gamepad's mapping defined this button,
  757. * as that is all the information SDL has about the physical device.
  758. *
  759. * \param gamepad a gamepad
  760. * \param button a button enum value (an SDL_GamepadButton value)
  761. * \returns SDL_TRUE if the gamepad has this button, SDL_FALSE otherwise.
  762. *
  763. * \since This function is available since SDL 3.0.0.
  764. */
  765. extern DECLSPEC SDL_bool SDLCALL SDL_GamepadHasButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  766. /**
  767. * Get the current state of a button on a gamepad.
  768. *
  769. * \param gamepad a gamepad
  770. * \param button a button index (one of the SDL_GamepadButton values)
  771. * \returns 1 for pressed state or 0 for not pressed state or error; call
  772. * SDL_GetError() for more information.
  773. *
  774. * \since This function is available since SDL 3.0.0.
  775. *
  776. * \sa SDL_GetGamepadAxis
  777. */
  778. extern DECLSPEC Uint8 SDLCALL SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  779. /**
  780. * Get the number of touchpads on a gamepad.
  781. *
  782. * \since This function is available since SDL 3.0.0.
  783. */
  784. extern DECLSPEC int SDLCALL SDL_GetGamepadNumTouchpads(SDL_Gamepad *gamepad);
  785. /**
  786. * Get the number of supported simultaneous fingers on a touchpad on a game
  787. * gamepad.
  788. *
  789. * \since This function is available since SDL 3.0.0.
  790. */
  791. extern DECLSPEC int SDLCALL SDL_GetGamepadNumTouchpadFingers(SDL_Gamepad *gamepad, int touchpad);
  792. /**
  793. * Get the current state of a finger on a touchpad on a gamepad.
  794. *
  795. * \since This function is available since SDL 3.0.0.
  796. */
  797. extern DECLSPEC int SDLCALL SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure);
  798. /**
  799. * Return whether a gamepad has a particular sensor.
  800. *
  801. * \param gamepad The gamepad to query
  802. * \param type The type of sensor to query
  803. * \returns SDL_TRUE if the sensor exists, SDL_FALSE otherwise.
  804. *
  805. * \since This function is available since SDL 3.0.0.
  806. */
  807. extern DECLSPEC SDL_bool SDLCALL SDL_GamepadHasSensor(SDL_Gamepad *gamepad, SDL_SensorType type);
  808. /**
  809. * Set whether data reporting for a gamepad sensor is enabled.
  810. *
  811. * \param gamepad The gamepad to update
  812. * \param type The type of sensor to enable/disable
  813. * \param enabled Whether data reporting should be enabled
  814. * \returns 0 or -1 if an error occurred.
  815. *
  816. * \since This function is available since SDL 3.0.0.
  817. */
  818. extern DECLSPEC int SDLCALL SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, SDL_bool enabled);
  819. /**
  820. * Query whether sensor data reporting is enabled for a gamepad.
  821. *
  822. * \param gamepad The gamepad to query
  823. * \param type The type of sensor to query
  824. * \returns SDL_TRUE if the sensor is enabled, SDL_FALSE otherwise.
  825. *
  826. * \since This function is available since SDL 3.0.0.
  827. */
  828. extern DECLSPEC SDL_bool SDLCALL SDL_GamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type);
  829. /**
  830. * Get the data rate (number of events per second) of a gamepad
  831. * sensor.
  832. *
  833. * \param gamepad The gamepad to query
  834. * \param type The type of sensor to query
  835. * \return the data rate, or 0.0f if the data rate is not available.
  836. *
  837. * \since This function is available since SDL 3.0.0.
  838. */
  839. extern DECLSPEC float SDLCALL SDL_GetGamepadSensorDataRate(SDL_Gamepad *gamepad, SDL_SensorType type);
  840. /**
  841. * Get the current state of a gamepad sensor.
  842. *
  843. * The number of values and interpretation of the data is sensor dependent.
  844. * See SDL_sensor.h for the details for each type of sensor.
  845. *
  846. * \param gamepad The gamepad to query
  847. * \param type The type of sensor to query
  848. * \param data A pointer filled with the current sensor state
  849. * \param num_values The number of values to write to data
  850. * \return 0 or -1 if an error occurred.
  851. *
  852. * \since This function is available since SDL 3.0.0.
  853. */
  854. extern DECLSPEC int SDLCALL SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, SDL_SensorType type, float *data, int num_values);
  855. /**
  856. * Start a rumble effect on a gamepad.
  857. *
  858. * Each call to this function cancels any previous rumble effect, and calling
  859. * it with 0 intensity stops any rumbling.
  860. *
  861. * \param gamepad The gamepad to vibrate
  862. * \param low_frequency_rumble The intensity of the low frequency (left)
  863. * rumble motor, from 0 to 0xFFFF
  864. * \param high_frequency_rumble The intensity of the high frequency (right)
  865. * rumble motor, from 0 to 0xFFFF
  866. * \param duration_ms The duration of the rumble effect, in milliseconds
  867. * \returns 0, or -1 if rumble isn't supported on this gamepad
  868. *
  869. * \since This function is available since SDL 3.0.0.
  870. *
  871. * \sa SDL_GamepadHasRumble
  872. */
  873. extern DECLSPEC int SDLCALL SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
  874. /**
  875. * Start a rumble effect in the gamepad's triggers.
  876. *
  877. * Each call to this function cancels any previous trigger rumble effect, and
  878. * calling it with 0 intensity stops any rumbling.
  879. *
  880. * Note that this is rumbling of the _triggers_ and not the gamepad as
  881. * a whole. This is currently only supported on Xbox One gamepads. If you
  882. * want the (more common) whole-gamepad rumble, use
  883. * SDL_RumbleGamepad() instead.
  884. *
  885. * \param gamepad The gamepad to vibrate
  886. * \param left_rumble The intensity of the left trigger rumble motor, from 0
  887. * to 0xFFFF
  888. * \param right_rumble The intensity of the right trigger rumble motor, from 0
  889. * to 0xFFFF
  890. * \param duration_ms The duration of the rumble effect, in milliseconds
  891. * \returns 0, or -1 if trigger rumble isn't supported on this gamepad
  892. *
  893. * \since This function is available since SDL 3.0.0.
  894. *
  895. * \sa SDL_GamepadHasRumbleTriggers
  896. */
  897. extern DECLSPEC int SDLCALL SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
  898. /**
  899. * Query whether a gamepad has an LED.
  900. *
  901. * \param gamepad The gamepad to query
  902. * \returns SDL_TRUE, or SDL_FALSE if this gamepad does not have a
  903. * modifiable LED
  904. *
  905. * \since This function is available since SDL 3.0.0.
  906. */
  907. extern DECLSPEC SDL_bool SDLCALL SDL_GamepadHasLED(SDL_Gamepad *gamepad);
  908. /**
  909. * Query whether a gamepad has rumble support.
  910. *
  911. * \param gamepad The gamepad to query
  912. * \returns SDL_TRUE, or SDL_FALSE if this gamepad does not have rumble
  913. * support
  914. *
  915. * \since This function is available since SDL 3.0.0.
  916. *
  917. * \sa SDL_RumbleGamepad
  918. */
  919. extern DECLSPEC SDL_bool SDLCALL SDL_GamepadHasRumble(SDL_Gamepad *gamepad);
  920. /**
  921. * Query whether a gamepad has rumble support on triggers.
  922. *
  923. * \param gamepad The gamepad to query
  924. * \returns SDL_TRUE, or SDL_FALSE if this gamepad does not have trigger
  925. * rumble support
  926. *
  927. * \since This function is available since SDL 3.0.0.
  928. *
  929. * \sa SDL_RumbleGamepadTriggers
  930. */
  931. extern DECLSPEC SDL_bool SDLCALL SDL_GamepadHasRumbleTriggers(SDL_Gamepad *gamepad);
  932. /**
  933. * Update a gamepad's LED color.
  934. *
  935. * \param gamepad The gamepad to update
  936. * \param red The intensity of the red LED
  937. * \param green The intensity of the green LED
  938. * \param blue The intensity of the blue LED
  939. * \returns 0, or -1 if this gamepad does not have a modifiable LED
  940. *
  941. * \since This function is available since SDL 3.0.0.
  942. */
  943. extern DECLSPEC int SDLCALL SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue);
  944. /**
  945. * Send a gamepad specific effect packet
  946. *
  947. * \param gamepad The gamepad to affect
  948. * \param data The data to send to the gamepad
  949. * \param size The size of the data to send to the gamepad
  950. * \returns 0, or -1 if this gamepad or driver doesn't support effect
  951. * packets
  952. *
  953. * \since This function is available since SDL 3.0.0.
  954. */
  955. extern DECLSPEC int SDLCALL SDL_SendGamepadEffect(SDL_Gamepad *gamepad, const void *data, int size);
  956. /**
  957. * Close a gamepad previously opened with SDL_OpenGamepad().
  958. *
  959. * \param gamepad a gamepad identifier previously returned by SDL_OpenGamepad()
  960. *
  961. * \since This function is available since SDL 3.0.0.
  962. *
  963. * \sa SDL_OpenGamepad
  964. */
  965. extern DECLSPEC void SDLCALL SDL_CloseGamepad(SDL_Gamepad *gamepad);
  966. /**
  967. * Return the sfSymbolsName for a given button on a gamepad on Apple
  968. * platforms.
  969. *
  970. * \param gamepad the gamepad to query
  971. * \param button a button on the gamepad
  972. * \returns the sfSymbolsName or NULL if the name can't be found
  973. *
  974. * \since This function is available since SDL 3.0.0.
  975. *
  976. * \sa SDL_GetGamepadAppleSFSymbolsNameForAxis
  977. */
  978. extern DECLSPEC const char* SDLCALL SDL_GetGamepadAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  979. /**
  980. * Return the sfSymbolsName for a given axis on a gamepad on Apple
  981. * platforms.
  982. *
  983. * \param gamepad the gamepad to query
  984. * \param axis an axis on the gamepad
  985. * \returns the sfSymbolsName or NULL if the name can't be found
  986. *
  987. * \since This function is available since SDL 3.0.0.
  988. *
  989. * \sa SDL_GetGamepadAppleSFSymbolsNameForButton
  990. */
  991. extern DECLSPEC const char* SDLCALL SDL_GetGamepadAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  992. /* Ends C function definitions when using C++ */
  993. #ifdef __cplusplus
  994. }
  995. #endif
  996. #include <SDL3/SDL_close_code.h>
  997. #endif /* SDL_gamepad_h_ */