SDL_gamecontroller.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  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_gamecontroller.h
  20. *
  21. * Include file for SDL game controller event handling
  22. */
  23. #ifndef SDL_gamecontroller_h_
  24. #define SDL_gamecontroller_h_
  25. #include "SDL_stdinc.h"
  26. #include "SDL_error.h"
  27. #include "SDL_rwops.h"
  28. #include "SDL_sensor.h"
  29. #include "SDL_joystick.h"
  30. #include "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_gamecontroller.h
  37. *
  38. * In order to use these functions, SDL_Init() must have been called
  39. * with the ::SDL_INIT_GAMECONTROLLER flag. This causes SDL to scan the system
  40. * for game controllers, and load appropriate drivers.
  41. *
  42. * If you would like to receive controller 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 gamecontroller structure used to identify an SDL game controller
  48. */
  49. struct _SDL_GameController;
  50. typedef struct _SDL_GameController SDL_GameController;
  51. typedef enum
  52. {
  53. SDL_CONTROLLER_TYPE_UNKNOWN = 0,
  54. SDL_CONTROLLER_TYPE_XBOX360,
  55. SDL_CONTROLLER_TYPE_XBOXONE,
  56. SDL_CONTROLLER_TYPE_PS3,
  57. SDL_CONTROLLER_TYPE_PS4,
  58. SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO,
  59. SDL_CONTROLLER_TYPE_VIRTUAL,
  60. SDL_CONTROLLER_TYPE_PS5,
  61. SDL_CONTROLLER_TYPE_AMAZON_LUNA,
  62. SDL_CONTROLLER_TYPE_GOOGLE_STADIA
  63. } SDL_GameControllerType;
  64. typedef enum
  65. {
  66. SDL_CONTROLLER_BINDTYPE_NONE = 0,
  67. SDL_CONTROLLER_BINDTYPE_BUTTON,
  68. SDL_CONTROLLER_BINDTYPE_AXIS,
  69. SDL_CONTROLLER_BINDTYPE_HAT
  70. } SDL_GameControllerBindType;
  71. /**
  72. * Get the SDL joystick layer binding for this controller button/axis mapping
  73. */
  74. typedef struct SDL_GameControllerButtonBind
  75. {
  76. SDL_GameControllerBindType bindType;
  77. union
  78. {
  79. int button;
  80. int axis;
  81. struct {
  82. int hat;
  83. int hat_mask;
  84. } hat;
  85. } value;
  86. } SDL_GameControllerButtonBind;
  87. /**
  88. * To count the number of game controllers in the system for the following:
  89. *
  90. * ```c
  91. * int nJoysticks = SDL_NumJoysticks();
  92. * int nGameControllers = 0;
  93. * for (int i = 0; i < nJoysticks; i++) {
  94. * if (SDL_IsGameController(i)) {
  95. * nGameControllers++;
  96. * }
  97. * }
  98. * ```
  99. *
  100. * Using the SDL_HINT_GAMECONTROLLERCONFIG hint or the SDL_GameControllerAddMapping() you can add support for controllers SDL is unaware of or cause an existing controller to have a different binding. The format is:
  101. * guid,name,mappings
  102. *
  103. * Where GUID is the string value from SDL_JoystickGetGUIDString(), name is the human readable string for the device and mappings are controller mappings to joystick ones.
  104. * Under Windows there is a reserved GUID of "xinput" that covers any XInput devices.
  105. * The mapping format for joystick is:
  106. * bX - a joystick button, index X
  107. * hX.Y - hat X with value Y
  108. * aX - axis X of the joystick
  109. * Buttons can be used as a controller axis and vice versa.
  110. *
  111. * This string shows an example of a valid mapping for a controller
  112. *
  113. * ```c
  114. * "03000000341a00003608000000000000,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",
  115. * ```
  116. */
  117. /**
  118. * Load a set of Game Controller mappings from a seekable SDL data stream.
  119. *
  120. * You can call this function several times, if needed, to load different
  121. * database files.
  122. *
  123. * If a new mapping is loaded for an already known controller GUID, the later
  124. * version will overwrite the one currently loaded.
  125. *
  126. * Mappings not belonging to the current platform or with no platform field
  127. * specified will be ignored (i.e. mappings for Linux will be ignored in
  128. * Windows, etc).
  129. *
  130. * This function will load the text database entirely in memory before
  131. * processing it, so take this into consideration if you are in a memory
  132. * constrained environment.
  133. *
  134. * \param rw the data stream for the mappings to be added
  135. * \param freerw non-zero to close the stream after being read
  136. * \returns the number of mappings added or -1 on error; call SDL_GetError()
  137. * for more information.
  138. *
  139. * \since This function is available since SDL 2.0.2.
  140. *
  141. * \sa SDL_GameControllerAddMapping
  142. * \sa SDL_GameControllerAddMappingsFromFile
  143. * \sa SDL_GameControllerMappingForGUID
  144. */
  145. extern DECLSPEC int SDLCALL SDL_GameControllerAddMappingsFromRW(SDL_RWops * rw, int freerw);
  146. /**
  147. * Load a set of mappings from a file, filtered by the current SDL_GetPlatform()
  148. *
  149. * Convenience macro.
  150. */
  151. #define SDL_GameControllerAddMappingsFromFile(file) SDL_GameControllerAddMappingsFromRW(SDL_RWFromFile(file, "rb"), 1)
  152. /**
  153. * Add support for controllers that SDL is unaware of or to cause an existing
  154. * controller to have a different binding.
  155. *
  156. * The mapping string has the format "GUID,name,mapping", where GUID is the
  157. * string value from SDL_JoystickGetGUIDString(), name is the human readable
  158. * string for the device and mappings are controller mappings to joystick
  159. * ones. Under Windows there is a reserved GUID of "xinput" that covers all
  160. * XInput devices. The mapping format for joystick is: {| |bX |a joystick
  161. * button, index X |- |hX.Y |hat X with value Y |- |aX |axis X of the joystick
  162. * |} Buttons can be used as a controller axes and vice versa.
  163. *
  164. * This string shows an example of a valid mapping for a controller:
  165. *
  166. * ```c
  167. * "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"
  168. * ```
  169. *
  170. * \param mappingString the mapping string
  171. * \returns 1 if a new mapping is added, 0 if an existing mapping is updated,
  172. * -1 on error; call SDL_GetError() for more information.
  173. *
  174. * \since This function is available since SDL 2.0.0.
  175. *
  176. * \sa SDL_GameControllerMapping
  177. * \sa SDL_GameControllerMappingForGUID
  178. */
  179. extern DECLSPEC int SDLCALL SDL_GameControllerAddMapping(const char* mappingString);
  180. /**
  181. * Get the number of mappings installed.
  182. *
  183. * \returns the number of mappings.
  184. *
  185. * \since This function is available since SDL 2.0.6.
  186. */
  187. extern DECLSPEC int SDLCALL SDL_GameControllerNumMappings(void);
  188. /**
  189. * Get the mapping at a particular index.
  190. *
  191. * \returns the mapping string. Must be freed with SDL_free(). Returns NULL if
  192. * the index is out of range.
  193. *
  194. * \since This function is available since SDL 2.0.6.
  195. */
  196. extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForIndex(int mapping_index);
  197. /**
  198. * Get the game controller mapping string for a given GUID.
  199. *
  200. * The returned string must be freed with SDL_free().
  201. *
  202. * \param guid a structure containing the GUID for which a mapping is desired
  203. * \returns a mapping string or NULL on error; call SDL_GetError() for more
  204. * information.
  205. *
  206. * \since This function is available since SDL 2.0.0.
  207. *
  208. * \sa SDL_JoystickGetDeviceGUID
  209. * \sa SDL_JoystickGetGUID
  210. */
  211. extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid);
  212. /**
  213. * Get the current mapping of a Game Controller.
  214. *
  215. * The returned string must be freed with SDL_free().
  216. *
  217. * Details about mappings are discussed with SDL_GameControllerAddMapping().
  218. *
  219. * \param gamecontroller the game controller you want to get the current
  220. * mapping for
  221. * \returns a string that has the controller's mapping or NULL if no mapping
  222. * is available; call SDL_GetError() for more information.
  223. *
  224. * \since This function is available since SDL 2.0.0.
  225. *
  226. * \sa SDL_GameControllerAddMapping
  227. * \sa SDL_GameControllerMappingForGUID
  228. */
  229. extern DECLSPEC char * SDLCALL SDL_GameControllerMapping(SDL_GameController *gamecontroller);
  230. /**
  231. * Check if the given joystick is supported by the game controller interface.
  232. *
  233. * `joystick_index` is the same as the `device_index` passed to
  234. * SDL_JoystickOpen().
  235. *
  236. * \param joystick_index the device_index of a device, up to
  237. * SDL_NumJoysticks()
  238. * \returns SDL_TRUE if the given joystick is supported by the game controller
  239. * interface, SDL_FALSE if it isn't or it's an invalid index.
  240. *
  241. * \since This function is available since SDL 2.0.0.
  242. *
  243. * \sa SDL_GameControllerNameForIndex
  244. * \sa SDL_GameControllerOpen
  245. */
  246. extern DECLSPEC SDL_bool SDLCALL SDL_IsGameController(int joystick_index);
  247. /**
  248. * Get the implementation dependent name for the game controller.
  249. *
  250. * This function can be called before any controllers are opened.
  251. *
  252. * `joystick_index` is the same as the `device_index` passed to
  253. * SDL_JoystickOpen().
  254. *
  255. * \param joystick_index the device_index of a device, from zero to
  256. * SDL_NumJoysticks()-1
  257. * \returns the implementation-dependent name for the game controller, or NULL
  258. * if there is no name or the index is invalid.
  259. *
  260. * \since This function is available since SDL 2.0.0.
  261. *
  262. * \sa SDL_GameControllerName
  263. * \sa SDL_GameControllerOpen
  264. * \sa SDL_IsGameController
  265. */
  266. extern DECLSPEC const char *SDLCALL SDL_GameControllerNameForIndex(int joystick_index);
  267. /**
  268. * Get the implementation dependent path for the game controller.
  269. *
  270. * This function can be called before any controllers are opened.
  271. *
  272. * `joystick_index` is the same as the `device_index` passed to
  273. * SDL_JoystickOpen().
  274. *
  275. * \param joystick_index the device_index of a device, from zero to
  276. * SDL_NumJoysticks()-1
  277. * \returns the implementation-dependent path for the game controller, or NULL
  278. * if there is no path or the index is invalid.
  279. *
  280. * \since This function is available since SDL 2.24.0.
  281. *
  282. * \sa SDL_GameControllerPath
  283. */
  284. extern DECLSPEC const char *SDLCALL SDL_GameControllerPathForIndex(int joystick_index);
  285. /**
  286. * Get the type of a game controller.
  287. *
  288. * This can be called before any controllers are opened.
  289. *
  290. * \param joystick_index the device_index of a device, from zero to
  291. * SDL_NumJoysticks()-1
  292. * \returns the controller type.
  293. *
  294. * \since This function is available since SDL 2.0.12.
  295. */
  296. extern DECLSPEC SDL_GameControllerType SDLCALL SDL_GameControllerTypeForIndex(int joystick_index);
  297. /**
  298. * Get the mapping of a game controller.
  299. *
  300. * This can be called before any controllers are opened.
  301. *
  302. * \param joystick_index the device_index of a device, from zero to
  303. * SDL_NumJoysticks()-1
  304. * \returns the mapping string. Must be freed with SDL_free(). Returns NULL if
  305. * no mapping is available.
  306. *
  307. * \since This function is available since SDL 2.0.9.
  308. */
  309. extern DECLSPEC char *SDLCALL SDL_GameControllerMappingForDeviceIndex(int joystick_index);
  310. /**
  311. * Open a game controller for use.
  312. *
  313. * `joystick_index` is the same as the `device_index` passed to
  314. * SDL_JoystickOpen().
  315. *
  316. * The index passed as an argument refers to the N'th game controller on the
  317. * system. This index is not the value which will identify this controller in
  318. * future controller events. The joystick's instance id (SDL_JoystickID) will
  319. * be used there instead.
  320. *
  321. * \param joystick_index the device_index of a device, up to
  322. * SDL_NumJoysticks()
  323. * \returns a gamecontroller identifier or NULL if an error occurred; call
  324. * SDL_GetError() for more information.
  325. *
  326. * \since This function is available since SDL 2.0.0.
  327. *
  328. * \sa SDL_GameControllerClose
  329. * \sa SDL_GameControllerNameForIndex
  330. * \sa SDL_IsGameController
  331. */
  332. extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerOpen(int joystick_index);
  333. /**
  334. * Get the SDL_GameController associated with an instance id.
  335. *
  336. * \param joyid the instance id to get the SDL_GameController for
  337. * \returns an SDL_GameController on success or NULL on failure; call
  338. * SDL_GetError() for more information.
  339. *
  340. * \since This function is available since SDL 2.0.4.
  341. */
  342. extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerFromInstanceID(SDL_JoystickID joyid);
  343. /**
  344. * Get the SDL_GameController associated with a player index.
  345. *
  346. * Please note that the player index is _not_ the device index, nor is it the
  347. * instance id!
  348. *
  349. * \param player_index the player index, which is not the device index or the
  350. * instance id!
  351. * \returns the SDL_GameController associated with a player index.
  352. *
  353. * \since This function is available since SDL 2.0.12.
  354. *
  355. * \sa SDL_GameControllerGetPlayerIndex
  356. * \sa SDL_GameControllerSetPlayerIndex
  357. */
  358. extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerFromPlayerIndex(int player_index);
  359. /**
  360. * Get the implementation-dependent name for an opened game controller.
  361. *
  362. * This is the same name as returned by SDL_GameControllerNameForIndex(), but
  363. * it takes a controller identifier instead of the (unstable) device index.
  364. *
  365. * \param gamecontroller a game controller identifier previously returned by
  366. * SDL_GameControllerOpen()
  367. * \returns the implementation dependent name for the game controller, or NULL
  368. * if there is no name or the identifier passed is invalid.
  369. *
  370. * \since This function is available since SDL 2.0.0.
  371. *
  372. * \sa SDL_GameControllerNameForIndex
  373. * \sa SDL_GameControllerOpen
  374. */
  375. extern DECLSPEC const char *SDLCALL SDL_GameControllerName(SDL_GameController *gamecontroller);
  376. /**
  377. * Get the implementation-dependent path for an opened game controller.
  378. *
  379. * This is the same path as returned by SDL_GameControllerNameForIndex(), but
  380. * it takes a controller identifier instead of the (unstable) device index.
  381. *
  382. * \param gamecontroller a game controller identifier previously returned by
  383. * SDL_GameControllerOpen()
  384. * \returns the implementation dependent path for the game controller, or NULL
  385. * if there is no path or the identifier passed is invalid.
  386. *
  387. * \since This function is available since SDL 2.24.0.
  388. *
  389. * \sa SDL_GameControllerPathForIndex
  390. */
  391. extern DECLSPEC const char *SDLCALL SDL_GameControllerPath(SDL_GameController *gamecontroller);
  392. /**
  393. * Get the type of this currently opened controller
  394. *
  395. * This is the same name as returned by SDL_GameControllerTypeForIndex(), but
  396. * it takes a controller identifier instead of the (unstable) device index.
  397. *
  398. * \param gamecontroller the game controller object to query.
  399. * \returns the controller type.
  400. *
  401. * \since This function is available since SDL 2.0.12.
  402. */
  403. extern DECLSPEC SDL_GameControllerType SDLCALL SDL_GameControllerGetType(SDL_GameController *gamecontroller);
  404. /**
  405. * Get the player index of an opened game controller.
  406. *
  407. * For XInput controllers this returns the XInput user index.
  408. *
  409. * \param gamecontroller the game controller object to query.
  410. * \returns the player index for controller, or -1 if it's not available.
  411. *
  412. * \since This function is available since SDL 2.0.9.
  413. */
  414. extern DECLSPEC int SDLCALL SDL_GameControllerGetPlayerIndex(SDL_GameController *gamecontroller);
  415. /**
  416. * Set the player index of an opened game controller.
  417. *
  418. * \param gamecontroller the game controller object to adjust.
  419. * \param player_index Player index to assign to this controller.
  420. *
  421. * \since This function is available since SDL 2.0.12.
  422. */
  423. extern DECLSPEC void SDLCALL SDL_GameControllerSetPlayerIndex(SDL_GameController *gamecontroller, int player_index);
  424. /**
  425. * Get the USB vendor ID of an opened controller, if available.
  426. *
  427. * If the vendor ID isn't available this function returns 0.
  428. *
  429. * \param gamecontroller the game controller object to query.
  430. * \return the USB vendor ID, or zero if unavailable.
  431. *
  432. * \since This function is available since SDL 2.0.6.
  433. */
  434. extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetVendor(SDL_GameController *gamecontroller);
  435. /**
  436. * Get the USB product ID of an opened controller, if available.
  437. *
  438. * If the product ID isn't available this function returns 0.
  439. *
  440. * \param gamecontroller the game controller object to query.
  441. * \return the USB product ID, or zero if unavailable.
  442. *
  443. * \since This function is available since SDL 2.0.6.
  444. */
  445. extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetProduct(SDL_GameController *gamecontroller);
  446. /**
  447. * Get the product version of an opened controller, if available.
  448. *
  449. * If the product version isn't available this function returns 0.
  450. *
  451. * \param gamecontroller the game controller object to query.
  452. * \return the USB product version, or zero if unavailable.
  453. *
  454. * \since This function is available since SDL 2.0.6.
  455. */
  456. extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetProductVersion(SDL_GameController *gamecontroller);
  457. /**
  458. * Get the serial number of an opened controller, if available.
  459. *
  460. * Returns the serial number of the controller, or NULL if it is not
  461. * available.
  462. *
  463. * \param gamecontroller the game controller object to query.
  464. * \return the serial number, or NULL if unavailable.
  465. *
  466. * \since This function is available since SDL 2.0.14.
  467. */
  468. extern DECLSPEC const char * SDLCALL SDL_GameControllerGetSerial(SDL_GameController *gamecontroller);
  469. /**
  470. * Check if a controller has been opened and is currently connected.
  471. *
  472. * \param gamecontroller a game controller identifier previously returned by
  473. * SDL_GameControllerOpen()
  474. * \returns SDL_TRUE if the controller has been opened and is currently
  475. * connected, or SDL_FALSE if not.
  476. *
  477. * \since This function is available since SDL 2.0.0.
  478. *
  479. * \sa SDL_GameControllerClose
  480. * \sa SDL_GameControllerOpen
  481. */
  482. extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerGetAttached(SDL_GameController *gamecontroller);
  483. /**
  484. * Get the Joystick ID from a Game Controller.
  485. *
  486. * This function will give you a SDL_Joystick object, which allows you to use
  487. * the SDL_Joystick functions with a SDL_GameController object. This would be
  488. * useful for getting a joystick's position at any given time, even if it
  489. * hasn't moved (moving it would produce an event, which would have the axis'
  490. * value).
  491. *
  492. * The pointer returned is owned by the SDL_GameController. You should not
  493. * call SDL_JoystickClose() on it, for example, since doing so will likely
  494. * cause SDL to crash.
  495. *
  496. * \param gamecontroller the game controller object that you want to get a
  497. * joystick from
  498. * \returns a SDL_Joystick object; call SDL_GetError() for more information.
  499. *
  500. * \since This function is available since SDL 2.0.0.
  501. */
  502. extern DECLSPEC SDL_Joystick *SDLCALL SDL_GameControllerGetJoystick(SDL_GameController *gamecontroller);
  503. /**
  504. * Query or change current state of Game Controller events.
  505. *
  506. * If controller events are disabled, you must call SDL_GameControllerUpdate()
  507. * yourself and check the state of the controller when you want controller
  508. * information.
  509. *
  510. * Any number can be passed to SDL_GameControllerEventState(), but only -1, 0,
  511. * and 1 will have any effect. Other numbers will just be returned.
  512. *
  513. * \param state can be one of `SDL_QUERY`, `SDL_IGNORE`, or `SDL_ENABLE`
  514. * \returns the same value passed to the function, with exception to -1
  515. * (SDL_QUERY), which will return the current state.
  516. *
  517. * \since This function is available since SDL 2.0.0.
  518. *
  519. * \sa SDL_JoystickEventState
  520. */
  521. extern DECLSPEC int SDLCALL SDL_GameControllerEventState(int state);
  522. /**
  523. * Manually pump game controller updates if not using the loop.
  524. *
  525. * This function is called automatically by the event loop if events are
  526. * enabled. Under such circumstances, it will not be necessary to call this
  527. * function.
  528. *
  529. * \since This function is available since SDL 2.0.0.
  530. */
  531. extern DECLSPEC void SDLCALL SDL_GameControllerUpdate(void);
  532. /**
  533. * The list of axes available from a controller
  534. *
  535. * Thumbstick axis values range from SDL_JOYSTICK_AXIS_MIN to SDL_JOYSTICK_AXIS_MAX,
  536. * and are centered within ~8000 of zero, though advanced UI will allow users to set
  537. * or autodetect the dead zone, which varies between controllers.
  538. *
  539. * Trigger axis values range from 0 to SDL_JOYSTICK_AXIS_MAX.
  540. */
  541. typedef enum
  542. {
  543. SDL_CONTROLLER_AXIS_INVALID = -1,
  544. SDL_CONTROLLER_AXIS_LEFTX,
  545. SDL_CONTROLLER_AXIS_LEFTY,
  546. SDL_CONTROLLER_AXIS_RIGHTX,
  547. SDL_CONTROLLER_AXIS_RIGHTY,
  548. SDL_CONTROLLER_AXIS_TRIGGERLEFT,
  549. SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
  550. SDL_CONTROLLER_AXIS_MAX
  551. } SDL_GameControllerAxis;
  552. /**
  553. * Convert a string into SDL_GameControllerAxis enum.
  554. *
  555. * This function is called internally to translate SDL_GameController mapping
  556. * strings for the underlying joystick device into the consistent
  557. * SDL_GameController mapping. You do not normally need to call this function
  558. * unless you are parsing SDL_GameController mappings in your own code.
  559. *
  560. * Note specially that "righttrigger" and "lefttrigger" map to
  561. * `SDL_CONTROLLER_AXIS_TRIGGERRIGHT` and `SDL_CONTROLLER_AXIS_TRIGGERLEFT`,
  562. * respectively.
  563. *
  564. * \param str string representing a SDL_GameController axis
  565. * \returns the SDL_GameControllerAxis enum corresponding to the input string,
  566. * or `SDL_CONTROLLER_AXIS_INVALID` if no match was found.
  567. *
  568. * \since This function is available since SDL 2.0.0.
  569. *
  570. * \sa SDL_GameControllerGetStringForAxis
  571. */
  572. extern DECLSPEC SDL_GameControllerAxis SDLCALL SDL_GameControllerGetAxisFromString(const char *str);
  573. /**
  574. * Convert from an SDL_GameControllerAxis enum to a string.
  575. *
  576. * The caller should not SDL_free() the returned string.
  577. *
  578. * \param axis an enum value for a given SDL_GameControllerAxis
  579. * \returns a string for the given axis, or NULL if an invalid axis is
  580. * specified. The string returned is of the format used by
  581. * SDL_GameController mapping strings.
  582. *
  583. * \since This function is available since SDL 2.0.0.
  584. *
  585. * \sa SDL_GameControllerGetAxisFromString
  586. */
  587. extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForAxis(SDL_GameControllerAxis axis);
  588. /**
  589. * Get the SDL joystick layer binding for a controller axis mapping.
  590. *
  591. * \param gamecontroller a game controller
  592. * \param axis an axis enum value (one of the SDL_GameControllerAxis values)
  593. * \returns a SDL_GameControllerButtonBind describing the bind. On failure
  594. * (like the given Controller axis doesn't exist on the device), its
  595. * `.bindType` will be `SDL_CONTROLLER_BINDTYPE_NONE`.
  596. *
  597. * \since This function is available since SDL 2.0.0.
  598. *
  599. * \sa SDL_GameControllerGetBindForButton
  600. */
  601. extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
  602. SDL_GameControllerGetBindForAxis(SDL_GameController *gamecontroller,
  603. SDL_GameControllerAxis axis);
  604. /**
  605. * Query whether a game controller has a given axis.
  606. *
  607. * This merely reports whether the controller's mapping defined this axis, as
  608. * that is all the information SDL has about the physical device.
  609. *
  610. * \param gamecontroller a game controller
  611. * \param axis an axis enum value (an SDL_GameControllerAxis value)
  612. * \returns SDL_TRUE if the controller has this axis, SDL_FALSE otherwise.
  613. *
  614. * \since This function is available since SDL 2.0.14.
  615. */
  616. extern DECLSPEC SDL_bool SDLCALL
  617. SDL_GameControllerHasAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis);
  618. /**
  619. * Get the current state of an axis control on a game controller.
  620. *
  621. * The axis indices start at index 0.
  622. *
  623. * The state is a value ranging from -32768 to 32767. Triggers, however, range
  624. * from 0 to 32767 (they never return a negative value).
  625. *
  626. * \param gamecontroller a game controller
  627. * \param axis an axis index (one of the SDL_GameControllerAxis values)
  628. * \returns axis state (including 0) on success or 0 (also) on failure; call
  629. * SDL_GetError() for more information.
  630. *
  631. * \since This function is available since SDL 2.0.0.
  632. *
  633. * \sa SDL_GameControllerGetButton
  634. */
  635. extern DECLSPEC Sint16 SDLCALL
  636. SDL_GameControllerGetAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis);
  637. /**
  638. * The list of buttons available from a controller
  639. */
  640. typedef enum
  641. {
  642. SDL_CONTROLLER_BUTTON_INVALID = -1,
  643. SDL_CONTROLLER_BUTTON_A,
  644. SDL_CONTROLLER_BUTTON_B,
  645. SDL_CONTROLLER_BUTTON_X,
  646. SDL_CONTROLLER_BUTTON_Y,
  647. SDL_CONTROLLER_BUTTON_BACK,
  648. SDL_CONTROLLER_BUTTON_GUIDE,
  649. SDL_CONTROLLER_BUTTON_START,
  650. SDL_CONTROLLER_BUTTON_LEFTSTICK,
  651. SDL_CONTROLLER_BUTTON_RIGHTSTICK,
  652. SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
  653. SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
  654. SDL_CONTROLLER_BUTTON_DPAD_UP,
  655. SDL_CONTROLLER_BUTTON_DPAD_DOWN,
  656. SDL_CONTROLLER_BUTTON_DPAD_LEFT,
  657. SDL_CONTROLLER_BUTTON_DPAD_RIGHT,
  658. SDL_CONTROLLER_BUTTON_MISC1, /* Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Amazon Luna microphone button */
  659. SDL_CONTROLLER_BUTTON_PADDLE1, /* Xbox Elite paddle P1 */
  660. SDL_CONTROLLER_BUTTON_PADDLE2, /* Xbox Elite paddle P3 */
  661. SDL_CONTROLLER_BUTTON_PADDLE3, /* Xbox Elite paddle P2 */
  662. SDL_CONTROLLER_BUTTON_PADDLE4, /* Xbox Elite paddle P4 */
  663. SDL_CONTROLLER_BUTTON_TOUCHPAD, /* PS4/PS5 touchpad button */
  664. SDL_CONTROLLER_BUTTON_MAX
  665. } SDL_GameControllerButton;
  666. /**
  667. * Convert a string into an SDL_GameControllerButton enum.
  668. *
  669. * This function is called internally to translate SDL_GameController mapping
  670. * strings for the underlying joystick device into the consistent
  671. * SDL_GameController mapping. You do not normally need to call this function
  672. * unless you are parsing SDL_GameController mappings in your own code.
  673. *
  674. * \param str string representing a SDL_GameController axis
  675. * \returns the SDL_GameControllerButton enum corresponding to the input
  676. * string, or `SDL_CONTROLLER_AXIS_INVALID` if no match was found.
  677. *
  678. * \since This function is available since SDL 2.0.0.
  679. */
  680. extern DECLSPEC SDL_GameControllerButton SDLCALL SDL_GameControllerGetButtonFromString(const char *str);
  681. /**
  682. * Convert from an SDL_GameControllerButton enum to a string.
  683. *
  684. * The caller should not SDL_free() the returned string.
  685. *
  686. * \param button an enum value for a given SDL_GameControllerButton
  687. * \returns a string for the given button, or NULL if an invalid axis is
  688. * specified. The string returned is of the format used by
  689. * SDL_GameController mapping strings.
  690. *
  691. * \since This function is available since SDL 2.0.0.
  692. *
  693. * \sa SDL_GameControllerGetButtonFromString
  694. */
  695. extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForButton(SDL_GameControllerButton button);
  696. /**
  697. * Get the SDL joystick layer binding for a controller button mapping.
  698. *
  699. * \param gamecontroller a game controller
  700. * \param button an button enum value (an SDL_GameControllerButton value)
  701. * \returns a SDL_GameControllerButtonBind describing the bind. On failure
  702. * (like the given Controller button doesn't exist on the device),
  703. * its `.bindType` will be `SDL_CONTROLLER_BINDTYPE_NONE`.
  704. *
  705. * \since This function is available since SDL 2.0.0.
  706. *
  707. * \sa SDL_GameControllerGetBindForAxis
  708. */
  709. extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
  710. SDL_GameControllerGetBindForButton(SDL_GameController *gamecontroller,
  711. SDL_GameControllerButton button);
  712. /**
  713. * Query whether a game controller has a given button.
  714. *
  715. * This merely reports whether the controller's mapping defined this button,
  716. * as that is all the information SDL has about the physical device.
  717. *
  718. * \param gamecontroller a game controller
  719. * \param button a button enum value (an SDL_GameControllerButton value)
  720. * \returns SDL_TRUE if the controller has this button, SDL_FALSE otherwise.
  721. *
  722. * \since This function is available since SDL 2.0.14.
  723. */
  724. extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasButton(SDL_GameController *gamecontroller,
  725. SDL_GameControllerButton button);
  726. /**
  727. * Get the current state of a button on a game controller.
  728. *
  729. * \param gamecontroller a game controller
  730. * \param button a button index (one of the SDL_GameControllerButton values)
  731. * \returns 1 for pressed state or 0 for not pressed state or error; call
  732. * SDL_GetError() for more information.
  733. *
  734. * \since This function is available since SDL 2.0.0.
  735. *
  736. * \sa SDL_GameControllerGetAxis
  737. */
  738. extern DECLSPEC Uint8 SDLCALL SDL_GameControllerGetButton(SDL_GameController *gamecontroller,
  739. SDL_GameControllerButton button);
  740. /**
  741. * Get the number of touchpads on a game controller.
  742. *
  743. * \since This function is available since SDL 2.0.14.
  744. */
  745. extern DECLSPEC int SDLCALL SDL_GameControllerGetNumTouchpads(SDL_GameController *gamecontroller);
  746. /**
  747. * Get the number of supported simultaneous fingers on a touchpad on a game
  748. * controller.
  749. *
  750. * \since This function is available since SDL 2.0.14.
  751. */
  752. extern DECLSPEC int SDLCALL SDL_GameControllerGetNumTouchpadFingers(SDL_GameController *gamecontroller, int touchpad);
  753. /**
  754. * Get the current state of a finger on a touchpad on a game controller.
  755. *
  756. * \since This function is available since SDL 2.0.14.
  757. */
  758. extern DECLSPEC int SDLCALL SDL_GameControllerGetTouchpadFinger(SDL_GameController *gamecontroller, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure);
  759. /**
  760. * Return whether a game controller has a particular sensor.
  761. *
  762. * \param gamecontroller The controller to query
  763. * \param type The type of sensor to query
  764. * \returns SDL_TRUE if the sensor exists, SDL_FALSE otherwise.
  765. *
  766. * \since This function is available since SDL 2.0.14.
  767. */
  768. extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasSensor(SDL_GameController *gamecontroller, SDL_SensorType type);
  769. /**
  770. * Set whether data reporting for a game controller sensor is enabled.
  771. *
  772. * \param gamecontroller The controller to update
  773. * \param type The type of sensor to enable/disable
  774. * \param enabled Whether data reporting should be enabled
  775. * \returns 0 or -1 if an error occurred.
  776. *
  777. * \since This function is available since SDL 2.0.14.
  778. */
  779. extern DECLSPEC int SDLCALL SDL_GameControllerSetSensorEnabled(SDL_GameController *gamecontroller, SDL_SensorType type, SDL_bool enabled);
  780. /**
  781. * Query whether sensor data reporting is enabled for a game controller.
  782. *
  783. * \param gamecontroller The controller to query
  784. * \param type The type of sensor to query
  785. * \returns SDL_TRUE if the sensor is enabled, SDL_FALSE otherwise.
  786. *
  787. * \since This function is available since SDL 2.0.14.
  788. */
  789. extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerIsSensorEnabled(SDL_GameController *gamecontroller, SDL_SensorType type);
  790. /**
  791. * Get the data rate (number of events per second) of a game controller
  792. * sensor.
  793. *
  794. * \param gamecontroller The controller to query
  795. * \param type The type of sensor to query
  796. * \return the data rate, or 0.0f if the data rate is not available.
  797. *
  798. * \since This function is available since SDL 2.0.16.
  799. */
  800. extern DECLSPEC float SDLCALL SDL_GameControllerGetSensorDataRate(SDL_GameController *gamecontroller, SDL_SensorType type);
  801. /**
  802. * Get the current state of a game controller sensor.
  803. *
  804. * The number of values and interpretation of the data is sensor dependent.
  805. * See SDL_sensor.h for the details for each type of sensor.
  806. *
  807. * \param gamecontroller The controller to query
  808. * \param type The type of sensor to query
  809. * \param data A pointer filled with the current sensor state
  810. * \param num_values The number of values to write to data
  811. * \return 0 or -1 if an error occurred.
  812. *
  813. * \since This function is available since SDL 2.0.14.
  814. */
  815. extern DECLSPEC int SDLCALL SDL_GameControllerGetSensorData(SDL_GameController *gamecontroller, SDL_SensorType type, float *data, int num_values);
  816. /**
  817. * Start a rumble effect on a game controller.
  818. *
  819. * Each call to this function cancels any previous rumble effect, and calling
  820. * it with 0 intensity stops any rumbling.
  821. *
  822. * \param gamecontroller The controller to vibrate
  823. * \param low_frequency_rumble The intensity of the low frequency (left)
  824. * rumble motor, from 0 to 0xFFFF
  825. * \param high_frequency_rumble The intensity of the high frequency (right)
  826. * rumble motor, from 0 to 0xFFFF
  827. * \param duration_ms The duration of the rumble effect, in milliseconds
  828. * \returns 0, or -1 if rumble isn't supported on this controller
  829. *
  830. * \since This function is available since SDL 2.0.9.
  831. *
  832. * \sa SDL_GameControllerHasRumble
  833. */
  834. extern DECLSPEC int SDLCALL SDL_GameControllerRumble(SDL_GameController *gamecontroller, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
  835. /**
  836. * Start a rumble effect in the game controller's triggers.
  837. *
  838. * Each call to this function cancels any previous trigger rumble effect, and
  839. * calling it with 0 intensity stops any rumbling.
  840. *
  841. * Note that this is rumbling of the _triggers_ and not the game controller as
  842. * a whole. This is currently only supported on Xbox One controllers. If you
  843. * want the (more common) whole-controller rumble, use
  844. * SDL_GameControllerRumble() instead.
  845. *
  846. * \param gamecontroller The controller to vibrate
  847. * \param left_rumble The intensity of the left trigger rumble motor, from 0
  848. * to 0xFFFF
  849. * \param right_rumble The intensity of the right trigger rumble motor, from 0
  850. * to 0xFFFF
  851. * \param duration_ms The duration of the rumble effect, in milliseconds
  852. * \returns 0, or -1 if trigger rumble isn't supported on this controller
  853. *
  854. * \since This function is available since SDL 2.0.14.
  855. *
  856. * \sa SDL_GameControllerHasRumbleTriggers
  857. */
  858. extern DECLSPEC int SDLCALL SDL_GameControllerRumbleTriggers(SDL_GameController *gamecontroller, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
  859. /**
  860. * Query whether a game controller has an LED.
  861. *
  862. * \param gamecontroller The controller to query
  863. * \returns SDL_TRUE, or SDL_FALSE if this controller does not have a
  864. * modifiable LED
  865. *
  866. * \since This function is available since SDL 2.0.14.
  867. */
  868. extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasLED(SDL_GameController *gamecontroller);
  869. /**
  870. * Query whether a game controller has rumble support.
  871. *
  872. * \param gamecontroller The controller to query
  873. * \returns SDL_TRUE, or SDL_FALSE if this controller does not have rumble
  874. * support
  875. *
  876. * \since This function is available since SDL 2.0.18.
  877. *
  878. * \sa SDL_GameControllerRumble
  879. */
  880. extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasRumble(SDL_GameController *gamecontroller);
  881. /**
  882. * Query whether a game controller has rumble support on triggers.
  883. *
  884. * \param gamecontroller The controller to query
  885. * \returns SDL_TRUE, or SDL_FALSE if this controller does not have trigger
  886. * rumble support
  887. *
  888. * \since This function is available since SDL 2.0.18.
  889. *
  890. * \sa SDL_GameControllerRumbleTriggers
  891. */
  892. extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasRumbleTriggers(SDL_GameController *gamecontroller);
  893. /**
  894. * Update a game controller's LED color.
  895. *
  896. * \param gamecontroller The controller to update
  897. * \param red The intensity of the red LED
  898. * \param green The intensity of the green LED
  899. * \param blue The intensity of the blue LED
  900. * \returns 0, or -1 if this controller does not have a modifiable LED
  901. *
  902. * \since This function is available since SDL 2.0.14.
  903. */
  904. extern DECLSPEC int SDLCALL SDL_GameControllerSetLED(SDL_GameController *gamecontroller, Uint8 red, Uint8 green, Uint8 blue);
  905. /**
  906. * Send a controller specific effect packet
  907. *
  908. * \param gamecontroller The controller to affect
  909. * \param data The data to send to the controller
  910. * \param size The size of the data to send to the controller
  911. * \returns 0, or -1 if this controller or driver doesn't support effect
  912. * packets
  913. *
  914. * \since This function is available since SDL 2.0.16.
  915. */
  916. extern DECLSPEC int SDLCALL SDL_GameControllerSendEffect(SDL_GameController *gamecontroller, const void *data, int size);
  917. /**
  918. * Close a game controller previously opened with SDL_GameControllerOpen().
  919. *
  920. * \param gamecontroller a game controller identifier previously returned by
  921. * SDL_GameControllerOpen()
  922. *
  923. * \since This function is available since SDL 2.0.0.
  924. *
  925. * \sa SDL_GameControllerOpen
  926. */
  927. extern DECLSPEC void SDLCALL SDL_GameControllerClose(SDL_GameController *gamecontroller);
  928. /**
  929. * Return the sfSymbolsName for a given button on a game controller on Apple
  930. * platforms.
  931. *
  932. * \param gamecontroller the controller to query
  933. * \param button a button on the game controller
  934. * \returns the sfSymbolsName or NULL if the name can't be found
  935. *
  936. * \since This function is available since SDL 2.0.18.
  937. *
  938. * \sa SDL_GameControllerGetAppleSFSymbolsNameForAxis
  939. */
  940. extern DECLSPEC const char* SDLCALL SDL_GameControllerGetAppleSFSymbolsNameForButton(SDL_GameController *gamecontroller, SDL_GameControllerButton button);
  941. /**
  942. * Return the sfSymbolsName for a given axis on a game controller on Apple
  943. * platforms.
  944. *
  945. * \param gamecontroller the controller to query
  946. * \param axis an axis on the game controller
  947. * \returns the sfSymbolsName or NULL if the name can't be found
  948. *
  949. * \since This function is available since SDL 2.0.18.
  950. *
  951. * \sa SDL_GameControllerGetAppleSFSymbolsNameForButton
  952. */
  953. extern DECLSPEC const char* SDLCALL SDL_GameControllerGetAppleSFSymbolsNameForAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis);
  954. /* Ends C function definitions when using C++ */
  955. #ifdef __cplusplus
  956. }
  957. #endif
  958. #include "close_code.h"
  959. #endif /* SDL_gamecontroller_h_ */
  960. /* vi: set ts=4 sw=4 expandtab: */