SDL_gamepad.h 36 KB

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