SDL_gamepad.h 36 KB

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