SDL_gamepad.h 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2022 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 Game Controller 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_GetJoystickDeviceGUID
  232. * \sa SDL_GetJoystickGUID
  233. */
  234. extern DECLSPEC char * SDLCALL SDL_GetGamepadMappingForGUID(SDL_JoystickGUID guid);
  235. /**
  236. * Get the current mapping of a Game Controller.
  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. * Check if the given joystick is supported by the gamepad interface.
  255. *
  256. * `joystick_index` is the same as the `device_index` passed to
  257. * SDL_OpenJoystick().
  258. *
  259. * \param joystick_index the device_index of a device, up to
  260. * SDL_GetNumJoysticks()
  261. * \returns SDL_TRUE if the given joystick is supported by the gamepad
  262. * interface, SDL_FALSE if it isn't or it's an invalid index.
  263. *
  264. * \since This function is available since SDL 3.0.0.
  265. *
  266. * \sa SDL_GetGamepadNameForIndex
  267. * \sa SDL_OpenGamepad
  268. */
  269. extern DECLSPEC SDL_bool SDLCALL SDL_IsGamepad(int joystick_index);
  270. /**
  271. * Get the implementation dependent name for the gamepad.
  272. *
  273. * This function can be called before any gamepads are opened.
  274. *
  275. * `joystick_index` is the same as the `device_index` passed to
  276. * SDL_OpenJoystick().
  277. *
  278. * \param joystick_index the device_index of a device, from zero to
  279. * SDL_GetNumJoysticks()-1
  280. * \returns the implementation-dependent name for the gamepad, or NULL
  281. * if there is no name or the index is invalid.
  282. *
  283. * \since This function is available since SDL 3.0.0.
  284. *
  285. * \sa SDL_GetGamepadName
  286. * \sa SDL_OpenGamepad
  287. * \sa SDL_IsGamepad
  288. */
  289. extern DECLSPEC const char *SDLCALL SDL_GetGamepadNameForIndex(int joystick_index);
  290. /**
  291. * Get the implementation dependent path for the gamepad.
  292. *
  293. * This function can be called before any gamepads are opened.
  294. *
  295. * `joystick_index` is the same as the `device_index` passed to
  296. * SDL_OpenJoystick().
  297. *
  298. * \param joystick_index the device_index of a device, from zero to
  299. * SDL_GetNumJoysticks()-1
  300. * \returns the implementation-dependent path for the gamepad, or NULL
  301. * if there is no path or the index is invalid.
  302. *
  303. * \since This function is available since SDL 3.0.0.
  304. *
  305. * \sa SDL_GetGamepadPath
  306. */
  307. extern DECLSPEC const char *SDLCALL SDL_GetGamepadPathForIndex(int joystick_index);
  308. /**
  309. * Get the type of a gamepad.
  310. *
  311. * This can be called before any gamepads are opened.
  312. *
  313. * \param joystick_index the device_index of a device, from zero to
  314. * SDL_GetNumJoysticks()-1
  315. * \returns the gamepad type.
  316. *
  317. * \since This function is available since SDL 3.0.0.
  318. */
  319. extern DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadTypeForIndex(int joystick_index);
  320. /**
  321. * Get the mapping of a gamepad.
  322. *
  323. * This can be called before any gamepads are opened.
  324. *
  325. * \param joystick_index the device_index of a device, from zero to
  326. * SDL_GetNumJoysticks()-1
  327. * \returns the mapping string. Must be freed with SDL_free(). Returns NULL if
  328. * no mapping is available.
  329. *
  330. * \since This function is available since SDL 3.0.0.
  331. */
  332. extern DECLSPEC char *SDLCALL SDL_GetGamepadMappingForDeviceIndex(int joystick_index);
  333. /**
  334. * Open a gamepad for use.
  335. *
  336. * `joystick_index` is the same as the `device_index` passed to
  337. * SDL_OpenJoystick().
  338. *
  339. * The index passed as an argument refers to the N'th gamepad on the
  340. * system. This index is not the value which will identify this gamepad in
  341. * future gamepad events. The joystick's instance id (SDL_JoystickID) will
  342. * be used there instead.
  343. *
  344. * \param joystick_index the device_index of a device, up to
  345. * SDL_GetNumJoysticks()
  346. * \returns a gamepad identifier or NULL if an error occurred; call
  347. * SDL_GetError() for more information.
  348. *
  349. * \since This function is available since SDL 3.0.0.
  350. *
  351. * \sa SDL_CloseGamepad
  352. * \sa SDL_GetGamepadNameForIndex
  353. * \sa SDL_IsGamepad
  354. */
  355. extern DECLSPEC SDL_Gamepad *SDLCALL SDL_OpenGamepad(int joystick_index);
  356. /**
  357. * Get the SDL_Gamepad associated with an instance id.
  358. *
  359. * \param joyid the instance id to get the SDL_Gamepad for
  360. * \returns an SDL_Gamepad on success or NULL on failure; call
  361. * SDL_GetError() for more information.
  362. *
  363. * \since This function is available since SDL 3.0.0.
  364. */
  365. extern DECLSPEC SDL_Gamepad *SDLCALL SDL_GetGamepadFromInstanceID(SDL_JoystickID joyid);
  366. /**
  367. * Get the SDL_Gamepad associated with a player index.
  368. *
  369. * Please note that the player index is _not_ the device index, nor is it the
  370. * instance id!
  371. *
  372. * \param player_index the player index, which is not the device index or the
  373. * instance id!
  374. * \returns the SDL_Gamepad associated with a player index.
  375. *
  376. * \since This function is available since SDL 3.0.0.
  377. *
  378. * \sa SDL_GetGamepadPlayerIndex
  379. * \sa SDL_SetGamepadPlayerIndex
  380. */
  381. extern DECLSPEC SDL_Gamepad *SDLCALL SDL_GetGamepadFromPlayerIndex(int player_index);
  382. /**
  383. * Get the implementation-dependent name for an opened gamepad.
  384. *
  385. * This is the same name as returned by SDL_GetGamepadNameForIndex(), but
  386. * it takes a gamepad identifier instead of the (unstable) device index.
  387. *
  388. * \param gamepad a gamepad identifier previously returned by
  389. * SDL_OpenGamepad()
  390. * \returns the implementation dependent name for the gamepad, or NULL
  391. * if there is no name or the identifier passed is invalid.
  392. *
  393. * \since This function is available since SDL 3.0.0.
  394. *
  395. * \sa SDL_GetGamepadNameForIndex
  396. * \sa SDL_OpenGamepad
  397. */
  398. extern DECLSPEC const char *SDLCALL SDL_GetGamepadName(SDL_Gamepad *gamepad);
  399. /**
  400. * Get the implementation-dependent path for an opened gamepad.
  401. *
  402. * This is the same path as returned by SDL_GetGamepadNameForIndex(), but
  403. * it takes a gamepad identifier instead of the (unstable) device index.
  404. *
  405. * \param gamepad a gamepad identifier previously returned by
  406. * SDL_OpenGamepad()
  407. * \returns the implementation dependent path for the gamepad, or NULL
  408. * if there is no path or the identifier passed is invalid.
  409. *
  410. * \since This function is available since SDL 3.0.0.
  411. *
  412. * \sa SDL_GetGamepadPathForIndex
  413. */
  414. extern DECLSPEC const char *SDLCALL SDL_GetGamepadPath(SDL_Gamepad *gamepad);
  415. /**
  416. * Get the type of this currently opened gamepad
  417. *
  418. * This is the same name as returned by SDL_GetGamepadTypeForIndex(), but
  419. * it takes a gamepad identifier instead of the (unstable) device index.
  420. *
  421. * \param gamepad the gamepad object to query.
  422. * \returns the gamepad type.
  423. *
  424. * \since This function is available since SDL 3.0.0.
  425. */
  426. extern DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadType(SDL_Gamepad *gamepad);
  427. /**
  428. * Get the player index of an opened gamepad.
  429. *
  430. * For XInput gamepads this returns the XInput user index.
  431. *
  432. * \param gamepad the gamepad object to query.
  433. * \returns the player index for gamepad, or -1 if it's not available.
  434. *
  435. * \since This function is available since SDL 3.0.0.
  436. */
  437. extern DECLSPEC int SDLCALL SDL_GetGamepadPlayerIndex(SDL_Gamepad *gamepad);
  438. /**
  439. * Set the player index of an opened gamepad.
  440. *
  441. * \param gamepad the gamepad object to adjust.
  442. * \param player_index Player index to assign to this gamepad, or -1 to
  443. * clear the player index and turn off player LEDs.
  444. *
  445. * \since This function is available since SDL 3.0.0.
  446. */
  447. extern DECLSPEC void SDLCALL SDL_SetGamepadPlayerIndex(SDL_Gamepad *gamepad, int player_index);
  448. /**
  449. * Get the USB vendor ID of an opened gamepad, if available.
  450. *
  451. * If the vendor ID isn't available this function returns 0.
  452. *
  453. * \param gamepad the gamepad object to query.
  454. * \return the USB vendor ID, or zero if unavailable.
  455. *
  456. * \since This function is available since SDL 3.0.0.
  457. */
  458. extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadVendor(SDL_Gamepad *gamepad);
  459. /**
  460. * Get the USB product ID of an opened gamepad, if available.
  461. *
  462. * If the product ID isn't available this function returns 0.
  463. *
  464. * \param gamepad the gamepad object to query.
  465. * \return the USB product ID, or zero if unavailable.
  466. *
  467. * \since This function is available since SDL 3.0.0.
  468. */
  469. extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadProduct(SDL_Gamepad *gamepad);
  470. /**
  471. * Get the product version of an opened gamepad, if available.
  472. *
  473. * If the product version isn't available this function returns 0.
  474. *
  475. * \param gamepad the gamepad object to query.
  476. * \return the USB product version, or zero if unavailable.
  477. *
  478. * \since This function is available since SDL 3.0.0.
  479. */
  480. extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductVersion(SDL_Gamepad *gamepad);
  481. /**
  482. * Get the firmware version of an opened gamepad, if available.
  483. *
  484. * If the firmware version isn't available this function returns 0.
  485. *
  486. * \param gamepad the gamepad object to query.
  487. * \return the gamepad firmware version, or zero if unavailable.
  488. *
  489. * \since This function is available since SDL 3.0.0.
  490. */
  491. extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadFirmwareVersion(SDL_Gamepad *gamepad);
  492. /**
  493. * Get the serial number of an opened gamepad, if available.
  494. *
  495. * Returns the serial number of the gamepad, or NULL if it is not
  496. * available.
  497. *
  498. * \param gamepad the gamepad object to query.
  499. * \return the serial number, or NULL if unavailable.
  500. *
  501. * \since This function is available since SDL 3.0.0.
  502. */
  503. extern DECLSPEC const char * SDLCALL SDL_GetGamepadSerial(SDL_Gamepad *gamepad);
  504. /**
  505. * Check if a gamepad has been opened and is currently connected.
  506. *
  507. * \param gamepad a gamepad identifier previously returned by
  508. * SDL_OpenGamepad()
  509. * \returns SDL_TRUE if the gamepad has been opened and is currently
  510. * connected, or SDL_FALSE if not.
  511. *
  512. * \since This function is available since SDL 3.0.0.
  513. *
  514. * \sa SDL_CloseGamepad
  515. * \sa SDL_OpenGamepad
  516. */
  517. extern DECLSPEC SDL_bool SDLCALL SDL_IsGamepadConnected(SDL_Gamepad *gamepad);
  518. /**
  519. * Get the Joystick ID from a Game Controller.
  520. *
  521. * This function will give you a SDL_Joystick object, which allows you to use
  522. * the SDL_Joystick functions with a SDL_Gamepad object. This would be
  523. * useful for getting a joystick's position at any given time, even if it
  524. * hasn't moved (moving it would produce an event, which would have the axis'
  525. * value).
  526. *
  527. * The pointer returned is owned by the SDL_Gamepad. You should not
  528. * call SDL_CloseJoystick() on it, for example, since doing so will likely
  529. * cause SDL to crash.
  530. *
  531. * \param gamepad the gamepad object that you want to get a
  532. * joystick from
  533. * \returns a SDL_Joystick object; call SDL_GetError() for more information.
  534. *
  535. * \since This function is available since SDL 3.0.0.
  536. */
  537. extern DECLSPEC SDL_Joystick *SDLCALL SDL_GetGamepadJoystick(SDL_Gamepad *gamepad);
  538. /**
  539. * Query or change current state of Game Controller events.
  540. *
  541. * If gamepad events are disabled, you must call SDL_UpdateGamepads()
  542. * yourself and check the state of the gamepad when you want gamepad
  543. * information.
  544. *
  545. * Any number can be passed to SDL_GetGamepadEventState(), but only -1, 0,
  546. * and 1 will have any effect. Other numbers will just be returned.
  547. *
  548. * \param state can be one of `SDL_QUERY`, `SDL_IGNORE`, or `SDL_ENABLE`
  549. * \returns the same value passed to the function, with exception to -1
  550. * (SDL_QUERY), which will return the current state.
  551. *
  552. * \since This function is available since SDL 3.0.0.
  553. *
  554. * \sa SDL_GetJoystickEventState
  555. */
  556. extern DECLSPEC int SDLCALL SDL_GetGamepadEventState(int state);
  557. /**
  558. * Manually pump gamepad updates if not using the loop.
  559. *
  560. * This function is called automatically by the event loop if events are
  561. * enabled. Under such circumstances, it will not be necessary to call this
  562. * function.
  563. *
  564. * \since This function is available since SDL 3.0.0.
  565. */
  566. extern DECLSPEC void SDLCALL SDL_UpdateGamepads(void);
  567. /**
  568. * Convert a string into SDL_GamepadAxis enum.
  569. *
  570. * This function is called internally to translate SDL_Gamepad mapping
  571. * strings for the underlying joystick device into the consistent
  572. * SDL_Gamepad mapping. You do not normally need to call this function
  573. * unless you are parsing SDL_Gamepad mappings in your own code.
  574. *
  575. * Note specially that "righttrigger" and "lefttrigger" map to
  576. * `SDL_GAMEPAD_AXIS_RIGHT_TRIGGER` and `SDL_GAMEPAD_AXIS_LEFT_TRIGGER`,
  577. * respectively.
  578. *
  579. * \param str string representing a SDL_Gamepad axis
  580. * \returns the SDL_GamepadAxis enum corresponding to the input string,
  581. * or `SDL_GAMEPAD_AXIS_INVALID` if no match was found.
  582. *
  583. * \since This function is available since SDL 3.0.0.
  584. *
  585. * \sa SDL_GetGamepadStringForAxis
  586. */
  587. extern DECLSPEC SDL_GamepadAxis SDLCALL SDL_GetGamepadAxisFromString(const char *str);
  588. /**
  589. * Convert from an SDL_GamepadAxis enum to a string.
  590. *
  591. * The caller should not SDL_free() the returned string.
  592. *
  593. * \param axis an enum value for a given SDL_GamepadAxis
  594. * \returns a string for the given axis, or NULL if an invalid axis is
  595. * specified. The string returned is of the format used by
  596. * SDL_Gamepad mapping strings.
  597. *
  598. * \since This function is available since SDL 3.0.0.
  599. *
  600. * \sa SDL_GetGamepadAxisFromString
  601. */
  602. extern DECLSPEC const char* SDLCALL SDL_GetGamepadStringForAxis(SDL_GamepadAxis axis);
  603. /**
  604. * Get the SDL joystick layer binding for a gamepad axis mapping.
  605. *
  606. * \param gamepad a gamepad
  607. * \param axis an axis enum value (one of the SDL_GamepadAxis values)
  608. * \returns a SDL_GamepadBinding describing the bind. On failure
  609. * (like the given Controller axis doesn't exist on the device), its
  610. * `.bindType` will be `SDL_GAMEPAD_BINDTYPE_NONE`.
  611. *
  612. * \since This function is available since SDL 3.0.0.
  613. *
  614. * \sa SDL_GetGamepadBindForButton
  615. */
  616. extern DECLSPEC SDL_GamepadBinding SDLCALL SDL_GetGamepadBindForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  617. /**
  618. * Query whether a gamepad has a given axis.
  619. *
  620. * This merely reports whether the gamepad's mapping defined this axis, as
  621. * that is all the information SDL has about the physical device.
  622. *
  623. * \param gamepad a gamepad
  624. * \param axis an axis enum value (an SDL_GamepadAxis value)
  625. * \returns SDL_TRUE if the gamepad has this axis, SDL_FALSE otherwise.
  626. *
  627. * \since This function is available since SDL 3.0.0.
  628. */
  629. extern DECLSPEC SDL_bool SDLCALL SDL_GamepadHasAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  630. /**
  631. * Get the current state of an axis control on a gamepad.
  632. *
  633. * The axis indices start at index 0.
  634. *
  635. * The state is a value ranging from -32768 to 32767. Triggers, however, range
  636. * from 0 to 32767 (they never return a negative value).
  637. *
  638. * \param gamepad a gamepad
  639. * \param axis an axis index (one of the SDL_GamepadAxis values)
  640. * \returns axis state (including 0) on success or 0 (also) on failure; call
  641. * SDL_GetError() for more information.
  642. *
  643. * \since This function is available since SDL 3.0.0.
  644. *
  645. * \sa SDL_GetGamepadButton
  646. */
  647. extern DECLSPEC Sint16 SDLCALL SDL_GetGamepadAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  648. /**
  649. * Convert a string into an SDL_GamepadButton enum.
  650. *
  651. * This function is called internally to translate SDL_Gamepad mapping
  652. * strings for the underlying joystick device into the consistent
  653. * SDL_Gamepad mapping. You do not normally need to call this function
  654. * unless you are parsing SDL_Gamepad mappings in your own code.
  655. *
  656. * \param str string representing a SDL_Gamepad axis
  657. * \returns the SDL_GamepadButton enum corresponding to the input
  658. * string, or `SDL_GAMEPAD_AXIS_INVALID` if no match was found.
  659. *
  660. * \since This function is available since SDL 3.0.0.
  661. */
  662. extern DECLSPEC SDL_GamepadButton SDLCALL SDL_GetGamepadButtonFromString(const char *str);
  663. /**
  664. * Convert from an SDL_GamepadButton enum to a string.
  665. *
  666. * The caller should not SDL_free() the returned string.
  667. *
  668. * \param button an enum value for a given SDL_GamepadButton
  669. * \returns a string for the given button, or NULL if an invalid button is
  670. * specified. The string returned is of the format used by
  671. * SDL_Gamepad mapping strings.
  672. *
  673. * \since This function is available since SDL 3.0.0.
  674. *
  675. * \sa SDL_GetGamepadButtonFromString
  676. */
  677. extern DECLSPEC const char* SDLCALL SDL_GetGamepadStringForButton(SDL_GamepadButton button);
  678. /**
  679. * Get the SDL joystick layer binding for a gamepad button mapping.
  680. *
  681. * \param gamepad a gamepad
  682. * \param button an button enum value (an SDL_GamepadButton value)
  683. * \returns a SDL_GamepadBinding describing the bind. On failure
  684. * (like the given Controller button doesn't exist on the device),
  685. * its `.bindType` will be `SDL_GAMEPAD_BINDTYPE_NONE`.
  686. *
  687. * \since This function is available since SDL 3.0.0.
  688. *
  689. * \sa SDL_GetGamepadBindForAxis
  690. */
  691. extern DECLSPEC SDL_GamepadBinding SDLCALL SDL_GetGamepadBindForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  692. /**
  693. * Query whether a gamepad has a given button.
  694. *
  695. * This merely reports whether the gamepad's mapping defined this button,
  696. * as that is all the information SDL has about the physical device.
  697. *
  698. * \param gamepad a gamepad
  699. * \param button a button enum value (an SDL_GamepadButton value)
  700. * \returns SDL_TRUE if the gamepad has this button, SDL_FALSE otherwise.
  701. *
  702. * \since This function is available since SDL 3.0.0.
  703. */
  704. extern DECLSPEC SDL_bool SDLCALL SDL_GamepadHasButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  705. /**
  706. * Get the current state of a button on a gamepad.
  707. *
  708. * \param gamepad a gamepad
  709. * \param button a button index (one of the SDL_GamepadButton values)
  710. * \returns 1 for pressed state or 0 for not pressed state or error; call
  711. * SDL_GetError() for more information.
  712. *
  713. * \since This function is available since SDL 3.0.0.
  714. *
  715. * \sa SDL_GetGamepadAxis
  716. */
  717. extern DECLSPEC Uint8 SDLCALL SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  718. /**
  719. * Get the number of touchpads on a gamepad.
  720. *
  721. * \since This function is available since SDL 3.0.0.
  722. */
  723. extern DECLSPEC int SDLCALL SDL_GetGamepadNumTouchpads(SDL_Gamepad *gamepad);
  724. /**
  725. * Get the number of supported simultaneous fingers on a touchpad on a game
  726. * gamepad.
  727. *
  728. * \since This function is available since SDL 3.0.0.
  729. */
  730. extern DECLSPEC int SDLCALL SDL_GetGamepadNumTouchpadFingers(SDL_Gamepad *gamepad, int touchpad);
  731. /**
  732. * Get the current state of a finger on a touchpad on a gamepad.
  733. *
  734. * \since This function is available since SDL 3.0.0.
  735. */
  736. extern DECLSPEC int SDLCALL SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure);
  737. /**
  738. * Return whether a gamepad has a particular sensor.
  739. *
  740. * \param gamepad The gamepad to query
  741. * \param type The type of sensor to query
  742. * \returns SDL_TRUE if the sensor exists, SDL_FALSE otherwise.
  743. *
  744. * \since This function is available since SDL 3.0.0.
  745. */
  746. extern DECLSPEC SDL_bool SDLCALL SDL_GamepadHasSensor(SDL_Gamepad *gamepad, SDL_SensorType type);
  747. /**
  748. * Set whether data reporting for a gamepad sensor is enabled.
  749. *
  750. * \param gamepad The gamepad to update
  751. * \param type The type of sensor to enable/disable
  752. * \param enabled Whether data reporting should be enabled
  753. * \returns 0 or -1 if an error occurred.
  754. *
  755. * \since This function is available since SDL 3.0.0.
  756. */
  757. extern DECLSPEC int SDLCALL SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, SDL_bool enabled);
  758. /**
  759. * Query whether sensor data reporting is enabled for a gamepad.
  760. *
  761. * \param gamepad The gamepad to query
  762. * \param type The type of sensor to query
  763. * \returns SDL_TRUE if the sensor is enabled, SDL_FALSE otherwise.
  764. *
  765. * \since This function is available since SDL 3.0.0.
  766. */
  767. extern DECLSPEC SDL_bool SDLCALL SDL_IsGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type);
  768. /**
  769. * Get the data rate (number of events per second) of a gamepad
  770. * sensor.
  771. *
  772. * \param gamepad The gamepad to query
  773. * \param type The type of sensor to query
  774. * \return the data rate, or 0.0f if the data rate is not available.
  775. *
  776. * \since This function is available since SDL 3.0.0.
  777. */
  778. extern DECLSPEC float SDLCALL SDL_GetGamepadSensorDataRate(SDL_Gamepad *gamepad, SDL_SensorType type);
  779. /**
  780. * Get the current state of a gamepad sensor.
  781. *
  782. * The number of values and interpretation of the data is sensor dependent.
  783. * See SDL_sensor.h for the details for each type of sensor.
  784. *
  785. * \param gamepad The gamepad to query
  786. * \param type The type of sensor to query
  787. * \param data A pointer filled with the current sensor state
  788. * \param num_values The number of values to write to data
  789. * \return 0 or -1 if an error occurred.
  790. *
  791. * \since This function is available since SDL 3.0.0.
  792. */
  793. extern DECLSPEC int SDLCALL SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, SDL_SensorType type, float *data, int num_values);
  794. /**
  795. * Start a rumble effect on a gamepad.
  796. *
  797. * Each call to this function cancels any previous rumble effect, and calling
  798. * it with 0 intensity stops any rumbling.
  799. *
  800. * \param gamepad The gamepad to vibrate
  801. * \param low_frequency_rumble The intensity of the low frequency (left)
  802. * rumble motor, from 0 to 0xFFFF
  803. * \param high_frequency_rumble The intensity of the high frequency (right)
  804. * rumble motor, from 0 to 0xFFFF
  805. * \param duration_ms The duration of the rumble effect, in milliseconds
  806. * \returns 0, or -1 if rumble isn't supported on this gamepad
  807. *
  808. * \since This function is available since SDL 3.0.0.
  809. *
  810. * \sa SDL_GamepadHasRumble
  811. */
  812. extern DECLSPEC int SDLCALL SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
  813. /**
  814. * Start a rumble effect in the gamepad's triggers.
  815. *
  816. * Each call to this function cancels any previous trigger rumble effect, and
  817. * calling it with 0 intensity stops any rumbling.
  818. *
  819. * Note that this is rumbling of the _triggers_ and not the gamepad as
  820. * a whole. This is currently only supported on Xbox One gamepads. If you
  821. * want the (more common) whole-gamepad rumble, use
  822. * SDL_RumbleGamepad() instead.
  823. *
  824. * \param gamepad The gamepad to vibrate
  825. * \param left_rumble The intensity of the left trigger rumble motor, from 0
  826. * to 0xFFFF
  827. * \param right_rumble The intensity of the right trigger rumble motor, from 0
  828. * to 0xFFFF
  829. * \param duration_ms The duration of the rumble effect, in milliseconds
  830. * \returns 0, or -1 if trigger rumble isn't supported on this gamepad
  831. *
  832. * \since This function is available since SDL 3.0.0.
  833. *
  834. * \sa SDL_GamepadHasRumbleTriggers
  835. */
  836. extern DECLSPEC int SDLCALL SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
  837. /**
  838. * Query whether a gamepad has an LED.
  839. *
  840. * \param gamepad The gamepad to query
  841. * \returns SDL_TRUE, or SDL_FALSE if this gamepad does not have a
  842. * modifiable LED
  843. *
  844. * \since This function is available since SDL 3.0.0.
  845. */
  846. extern DECLSPEC SDL_bool SDLCALL SDL_GamepadHasLED(SDL_Gamepad *gamepad);
  847. /**
  848. * Query whether a gamepad has rumble support.
  849. *
  850. * \param gamepad The gamepad to query
  851. * \returns SDL_TRUE, or SDL_FALSE if this gamepad does not have rumble
  852. * support
  853. *
  854. * \since This function is available since SDL 3.0.0.
  855. *
  856. * \sa SDL_RumbleGamepad
  857. */
  858. extern DECLSPEC SDL_bool SDLCALL SDL_GamepadHasRumble(SDL_Gamepad *gamepad);
  859. /**
  860. * Query whether a gamepad has rumble support on triggers.
  861. *
  862. * \param gamepad The gamepad to query
  863. * \returns SDL_TRUE, or SDL_FALSE if this gamepad does not have trigger
  864. * rumble support
  865. *
  866. * \since This function is available since SDL 3.0.0.
  867. *
  868. * \sa SDL_RumbleGamepadTriggers
  869. */
  870. extern DECLSPEC SDL_bool SDLCALL SDL_GamepadHasRumbleTriggers(SDL_Gamepad *gamepad);
  871. /**
  872. * Update a gamepad's LED color.
  873. *
  874. * \param gamepad The gamepad to update
  875. * \param red The intensity of the red LED
  876. * \param green The intensity of the green LED
  877. * \param blue The intensity of the blue LED
  878. * \returns 0, or -1 if this gamepad does not have a modifiable LED
  879. *
  880. * \since This function is available since SDL 3.0.0.
  881. */
  882. extern DECLSPEC int SDLCALL SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue);
  883. /**
  884. * Send a gamepad specific effect packet
  885. *
  886. * \param gamepad The gamepad to affect
  887. * \param data The data to send to the gamepad
  888. * \param size The size of the data to send to the gamepad
  889. * \returns 0, or -1 if this gamepad or driver doesn't support effect
  890. * packets
  891. *
  892. * \since This function is available since SDL 3.0.0.
  893. */
  894. extern DECLSPEC int SDLCALL SDL_SendGamepadEffect(SDL_Gamepad *gamepad, const void *data, int size);
  895. /**
  896. * Close a gamepad previously opened with SDL_OpenGamepad().
  897. *
  898. * \param gamepad a gamepad identifier previously returned by SDL_OpenGamepad()
  899. *
  900. * \since This function is available since SDL 3.0.0.
  901. *
  902. * \sa SDL_OpenGamepad
  903. */
  904. extern DECLSPEC void SDLCALL SDL_CloseGamepad(SDL_Gamepad *gamepad);
  905. /**
  906. * Return the sfSymbolsName for a given button on a gamepad on Apple
  907. * platforms.
  908. *
  909. * \param gamepad the gamepad to query
  910. * \param button a button on the gamepad
  911. * \returns the sfSymbolsName or NULL if the name can't be found
  912. *
  913. * \since This function is available since SDL 3.0.0.
  914. *
  915. * \sa SDL_GetGamepadAppleSFSymbolsNameForAxis
  916. */
  917. extern DECLSPEC const char* SDLCALL SDL_GetGamepadAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  918. /**
  919. * Return the sfSymbolsName for a given axis on a gamepad on Apple
  920. * platforms.
  921. *
  922. * \param gamepad the gamepad to query
  923. * \param axis an axis on the gamepad
  924. * \returns the sfSymbolsName or NULL if the name can't be found
  925. *
  926. * \since This function is available since SDL 3.0.0.
  927. *
  928. * \sa SDL_GetGamepadAppleSFSymbolsNameForButton
  929. */
  930. extern DECLSPEC const char* SDLCALL SDL_GetGamepadAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  931. /* Ends C function definitions when using C++ */
  932. #ifdef __cplusplus
  933. }
  934. #endif
  935. #include <SDL3/SDL_close_code.h>
  936. #endif /* SDL_gamepad_h_ */