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