2 Simple DirectMedia Layer
3 Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
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.
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:
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.
23 * \file SDL_gamecontroller.h
25 * Include file for SDL game controller event handling
28 #ifndef SDL_gamecontroller_h_
29 #define SDL_gamecontroller_h_
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"
37 #include "begin_code.h"
38 /* Set up for C function definitions, even when using C++ */
44 * \file SDL_gamecontroller.h
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.
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
56 * The gamecontroller structure used to identify an SDL game controller
58 struct _SDL_GameController;
59 typedef struct _SDL_GameController SDL_GameController;
63 SDL_CONTROLLER_TYPE_UNKNOWN = 0,
64 SDL_CONTROLLER_TYPE_XBOX360,
65 SDL_CONTROLLER_TYPE_XBOXONE,
66 SDL_CONTROLLER_TYPE_PS3,
67 SDL_CONTROLLER_TYPE_PS4,
68 SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO,
69 SDL_CONTROLLER_TYPE_VIRTUAL,
70 SDL_CONTROLLER_TYPE_PS5,
71 SDL_CONTROLLER_TYPE_AMAZON_LUNA,
72 SDL_CONTROLLER_TYPE_GOOGLE_STADIA
73 } SDL_GameControllerType;
77 SDL_CONTROLLER_BINDTYPE_NONE = 0,
78 SDL_CONTROLLER_BINDTYPE_BUTTON,
79 SDL_CONTROLLER_BINDTYPE_AXIS,
80 SDL_CONTROLLER_BINDTYPE_HAT
81 } SDL_GameControllerBindType;
84 * Get the SDL joystick layer binding for this controller button/axis mapping
86 typedef struct SDL_GameControllerButtonBind
88 SDL_GameControllerBindType bindType;
99 } SDL_GameControllerButtonBind;
103 * To count the number of game controllers in the system for the following:
106 * int nJoysticks = SDL_NumJoysticks();
107 * int nGameControllers = 0;
108 * for (int i = 0; i < nJoysticks; i++) {
109 * if (SDL_IsGameController(i)) {
110 * nGameControllers++;
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:
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.
126 * This string shows an example of a valid mapping for a controller
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",
134 * Load a set of Game Controller mappings from a seekable SDL data stream.
136 * You can call this function several times, if needed, to load different
139 * If a new mapping is loaded for an already known controller GUID, the later
140 * version will overwrite the one currently loaded.
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
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.
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.
155 * \since This function is available since SDL 2.0.2.
157 * \sa SDL_GameControllerAddMapping
158 * \sa SDL_GameControllerAddMappingsFromFile
159 * \sa SDL_GameControllerMappingForGUID
161 extern DECLSPEC int SDLCALL SDL_GameControllerAddMappingsFromRW(SDL_RWops * rw, int freerw);
164 * Load a set of mappings from a file, filtered by the current SDL_GetPlatform()
168 #define SDL_GameControllerAddMappingsFromFile(file) SDL_GameControllerAddMappingsFromRW(SDL_RWFromFile(file, "rb"), 1)
171 * Add support for controllers that SDL is unaware of or to cause an existing
172 * controller to have a different binding.
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.
182 * This string shows an example of a valid mapping for a controller:
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"
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.
192 * \since This function is available since SDL 2.0.0.
194 * \sa SDL_GameControllerMapping
195 * \sa SDL_GameControllerMappingForGUID
197 extern DECLSPEC int SDLCALL SDL_GameControllerAddMapping(const char* mappingString);
200 * Get the number of mappings installed.
202 * \returns the number of mappings.
204 * \since This function is available since SDL 2.0.6.
206 extern DECLSPEC int SDLCALL SDL_GameControllerNumMappings(void);
209 * Get the mapping at a particular index.
211 * \returns the mapping string. Must be freed with SDL_free(). Returns NULL if
212 * the index is out of range.
214 * \since This function is available since SDL 2.0.6.
216 extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForIndex(int mapping_index);
219 * Get the game controller mapping string for a given GUID.
221 * The returned string must be freed with SDL_free().
223 * \param guid a structure containing the GUID for which a mapping is desired
224 * \returns a mapping string or NULL on error; call SDL_GetError() for more
227 * \since This function is available since SDL 2.0.0.
229 * \sa SDL_JoystickGetDeviceGUID
230 * \sa SDL_JoystickGetGUID
232 extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid);
235 * Get the current mapping of a Game Controller.
237 * The returned string must be freed with SDL_free().
239 * Details about mappings are discussed with SDL_GameControllerAddMapping().
241 * \param gamecontroller the game controller you want to get the current
243 * \returns a string that has the controller's mapping or NULL if no mapping
244 * is available; call SDL_GetError() for more information.
246 * \since This function is available since SDL 2.0.0.
248 * \sa SDL_GameControllerAddMapping
249 * \sa SDL_GameControllerMappingForGUID
251 extern DECLSPEC char * SDLCALL SDL_GameControllerMapping(SDL_GameController *gamecontroller);
254 * Check if the given joystick is supported by the game controller interface.
256 * `joystick_index` is the same as the `device_index` passed to
257 * SDL_JoystickOpen().
259 * \param joystick_index the device_index of a device, up to
261 * \returns SDL_TRUE if the given joystick is supported by the game controller
262 * interface, SDL_FALSE if it isn't or it's an invalid index.
264 * \since This function is available since SDL 2.0.0.
266 * \sa SDL_GameControllerNameForIndex
267 * \sa SDL_GameControllerOpen
269 extern DECLSPEC SDL_bool SDLCALL SDL_IsGameController(int joystick_index);
272 * Get the implementation dependent name for the game controller.
274 * This function can be called before any controllers are opened.
276 * `joystick_index` is the same as the `device_index` passed to
277 * SDL_JoystickOpen().
279 * \param joystick_index the device_index of a device, from zero to
280 * SDL_NumJoysticks()-1
281 * \returns the implementation-dependent name for the game controller, or NULL
282 * if there is no name or the index is invalid.
284 * \since This function is available since SDL 2.0.0.
286 * \sa SDL_GameControllerName
287 * \sa SDL_GameControllerOpen
288 * \sa SDL_IsGameController
290 extern DECLSPEC const char *SDLCALL SDL_GameControllerNameForIndex(int joystick_index);
293 * Get the type of a game controller.
295 * This can be called before any controllers are opened.
297 * \param joystick_index the device_index of a device, from zero to
298 * SDL_NumJoysticks()-1
299 * \returns the controller type.
301 * \since This function is available since SDL 2.0.12.
303 extern DECLSPEC SDL_GameControllerType SDLCALL SDL_GameControllerTypeForIndex(int joystick_index);
306 * Get the mapping of a game controller.
308 * This can be called before any controllers are opened.
310 * \param joystick_index the device_index of a device, from zero to
311 * SDL_NumJoysticks()-1
312 * \returns the mapping string. Must be freed with SDL_free(). Returns NULL if
313 * no mapping is available.
315 * \since This function is available since SDL 2.0.9.
317 extern DECLSPEC char *SDLCALL SDL_GameControllerMappingForDeviceIndex(int joystick_index);
320 * Open a game controller for use.
322 * `joystick_index` is the same as the `device_index` passed to
323 * SDL_JoystickOpen().
325 * The index passed as an argument refers to the N'th game controller on the
326 * system. This index is not the value which will identify this controller in
327 * future controller events. The joystick's instance id (SDL_JoystickID) will
328 * be used there instead.
330 * \param joystick_index the device_index of a device, up to
332 * \returns a gamecontroller identifier or NULL if an error occurred; call
333 * SDL_GetError() for more information.
335 * \since This function is available since SDL 2.0.0.
337 * \sa SDL_GameControllerClose
338 * \sa SDL_GameControllerNameForIndex
339 * \sa SDL_IsGameController
341 extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerOpen(int joystick_index);
344 * Get the SDL_GameController associated with an instance id.
346 * \param joyid the instance id to get the SDL_GameController for
347 * \returns an SDL_GameController on success or NULL on failure; call
348 * SDL_GetError() for more information.
350 * \since This function is available since SDL 2.0.4.
352 extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerFromInstanceID(SDL_JoystickID joyid);
355 * Get the SDL_GameController associated with a player index.
357 * Please note that the player index is _not_ the device index, nor is it the
360 * \param player_index the player index, which is not the device index or the
362 * \returns the SDL_GameController associated with a player index.
364 * \since This function is available since SDL 2.0.12.
366 * \sa SDL_GameControllerGetPlayerIndex
367 * \sa SDL_GameControllerSetPlayerIndex
369 extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerFromPlayerIndex(int player_index);
372 * Get the implementation-dependent name for an opened game controller.
374 * This is the same name as returned by SDL_GameControllerNameForIndex(), but
375 * it takes a controller identifier instead of the (unstable) device index.
377 * \param gamecontroller a game controller identifier previously returned by
378 * SDL_GameControllerOpen()
379 * \returns the implementation dependent name for the game controller, or NULL
380 * if there is no name or the identifier passed is invalid.
382 * \since This function is available since SDL 2.0.0.
384 * \sa SDL_GameControllerNameForIndex
385 * \sa SDL_GameControllerOpen
387 extern DECLSPEC const char *SDLCALL SDL_GameControllerName(SDL_GameController *gamecontroller);
390 * Get the type of this currently opened controller
392 * This is the same name as returned by SDL_GameControllerTypeForIndex(), but
393 * it takes a controller identifier instead of the (unstable) device index.
395 * \param gamecontroller the game controller object to query.
396 * \returns the controller type.
398 * \since This function is available since SDL 2.0.12.
400 extern DECLSPEC SDL_GameControllerType SDLCALL SDL_GameControllerGetType(SDL_GameController *gamecontroller);
403 * Get the player index of an opened game controller.
405 * For XInput controllers this returns the XInput user index.
407 * \param gamecontroller the game controller object to query.
408 * \returns the player index for controller, or -1 if it's not available.
410 * \since This function is available since SDL 2.0.9.
412 extern DECLSPEC int SDLCALL SDL_GameControllerGetPlayerIndex(SDL_GameController *gamecontroller);
415 * Set the player index of an opened game controller.
417 * \param gamecontroller the game controller object to adjust.
418 * \param player_index Player index to assign to this controller.
420 * \since This function is available since SDL 2.0.12.
422 extern DECLSPEC void SDLCALL SDL_GameControllerSetPlayerIndex(SDL_GameController *gamecontroller, int player_index);
425 * Get the USB vendor ID of an opened controller, if available.
427 * If the vendor ID isn't available this function returns 0.
429 * \param gamecontroller the game controller object to query.
430 * \return the USB vendor ID, or zero if unavailable.
432 * \since This function is available since SDL 2.0.6.
434 extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetVendor(SDL_GameController *gamecontroller);
437 * Get the USB product ID of an opened controller, if available.
439 * If the product ID isn't available this function returns 0.
441 * \param gamecontroller the game controller object to query.
442 * \return the USB product ID, or zero if unavailable.
444 * \since This function is available since SDL 2.0.6.
446 extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetProduct(SDL_GameController *gamecontroller);
449 * Get the product version of an opened controller, if available.
451 * If the product version isn't available this function returns 0.
453 * \param gamecontroller the game controller object to query.
454 * \return the USB product version, or zero if unavailable.
456 * \since This function is available since SDL 2.0.6.
458 extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetProductVersion(SDL_GameController *gamecontroller);
461 * Get the serial number of an opened controller, if available.
463 * Returns the serial number of the controller, or NULL if it is not
466 * \param gamecontroller the game controller object to query.
467 * \return the serial number, or NULL if unavailable.
469 * \since This function is available since SDL 2.0.14.
471 extern DECLSPEC const char * SDLCALL SDL_GameControllerGetSerial(SDL_GameController *gamecontroller);
474 * Check if a controller has been opened and is currently connected.
476 * \param gamecontroller a game controller identifier previously returned by
477 * SDL_GameControllerOpen()
478 * \returns SDL_TRUE if the controller has been opened and is currently
479 * connected, or SDL_FALSE if not.
481 * \since This function is available since SDL 2.0.0.
483 * \sa SDL_GameControllerClose
484 * \sa SDL_GameControllerOpen
486 extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerGetAttached(SDL_GameController *gamecontroller);
489 * Get the Joystick ID from a Game Controller.
491 * This function will give you a SDL_Joystick object, which allows you to use
492 * the SDL_Joystick functions with a SDL_GameController object. This would be
493 * useful for getting a joystick's position at any given time, even if it
494 * hasn't moved (moving it would produce an event, which would have the axis'
497 * The pointer returned is owned by the SDL_GameController. You should not
498 * call SDL_JoystickClose() on it, for example, since doing so will likely
499 * cause SDL to crash.
501 * \param gamecontroller the game controller object that you want to get a
503 * \returns a SDL_Joystick object; call SDL_GetError() for more information.
505 * \since This function is available since SDL 2.0.0.
507 extern DECLSPEC SDL_Joystick *SDLCALL SDL_GameControllerGetJoystick(SDL_GameController *gamecontroller);
510 * Query or change current state of Game Controller events.
512 * If controller events are disabled, you must call SDL_GameControllerUpdate()
513 * yourself and check the state of the controller when you want controller
516 * Any number can be passed to SDL_GameControllerEventState(), but only -1, 0,
517 * and 1 will have any effect. Other numbers will just be returned.
519 * \param state can be one of `SDL_QUERY`, `SDL_IGNORE`, or `SDL_ENABLE`
520 * \returns the same value passed to the function, with exception to -1
521 * (SDL_QUERY), which will return the current state.
523 * \since This function is available since SDL 2.0.0.
525 * \sa SDL_JoystickEventState
527 extern DECLSPEC int SDLCALL SDL_GameControllerEventState(int state);
530 * Manually pump game controller updates if not using the loop.
532 * This function is called automatically by the event loop if events are
533 * enabled. Under such circumstances, it will not be necessary to call this
536 * \since This function is available since SDL 2.0.0.
538 extern DECLSPEC void SDLCALL SDL_GameControllerUpdate(void);
542 * The list of axes available from a controller
544 * Thumbstick axis values range from SDL_JOYSTICK_AXIS_MIN to SDL_JOYSTICK_AXIS_MAX,
545 * and are centered within ~8000 of zero, though advanced UI will allow users to set
546 * or autodetect the dead zone, which varies between controllers.
548 * Trigger axis values range from 0 to SDL_JOYSTICK_AXIS_MAX.
552 SDL_CONTROLLER_AXIS_INVALID = -1,
553 SDL_CONTROLLER_AXIS_LEFTX,
554 SDL_CONTROLLER_AXIS_LEFTY,
555 SDL_CONTROLLER_AXIS_RIGHTX,
556 SDL_CONTROLLER_AXIS_RIGHTY,
557 SDL_CONTROLLER_AXIS_TRIGGERLEFT,
558 SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
559 SDL_CONTROLLER_AXIS_MAX
560 } SDL_GameControllerAxis;
563 * Convert a string into SDL_GameControllerAxis enum.
565 * This function is called internally to translate SDL_GameController mapping
566 * strings for the underlying joystick device into the consistent
567 * SDL_GameController mapping. You do not normally need to call this function
568 * unless you are parsing SDL_GameController mappings in your own code.
570 * Note specially that "righttrigger" and "lefttrigger" map to
571 * `SDL_CONTROLLER_AXIS_TRIGGERRIGHT` and `SDL_CONTROLLER_AXIS_TRIGGERLEFT`,
574 * \param str string representing a SDL_GameController axis
575 * \returns the SDL_GameControllerAxis enum corresponding to the input string,
576 * or `SDL_CONTROLLER_AXIS_INVALID` if no match was found.
578 * \since This function is available since SDL 2.0.0.
580 * \sa SDL_GameControllerGetStringForAxis
582 extern DECLSPEC SDL_GameControllerAxis SDLCALL SDL_GameControllerGetAxisFromString(const char *str);
585 * Convert from an SDL_GameControllerAxis enum to a string.
587 * The caller should not SDL_free() the returned string.
589 * \param axis an enum value for a given SDL_GameControllerAxis
590 * \returns a string for the given axis, or NULL if an invalid axis is
591 * specified. The string returned is of the format used by
592 * SDL_GameController mapping strings.
594 * \since This function is available since SDL 2.0.0.
596 * \sa SDL_GameControllerGetAxisFromString
598 extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForAxis(SDL_GameControllerAxis axis);
601 * Get the SDL joystick layer binding for a controller axis mapping.
603 * \param gamecontroller a game controller
604 * \param axis an axis enum value (one of the SDL_GameControllerAxis values)
605 * \returns a SDL_GameControllerButtonBind describing the bind. On failure
606 * (like the given Controller axis doesn't exist on the device), its
607 * `.bindType` will be `SDL_CONTROLLER_BINDTYPE_NONE`.
609 * \since This function is available since SDL 2.0.0.
611 * \sa SDL_GameControllerGetBindForButton
613 extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
614 SDL_GameControllerGetBindForAxis(SDL_GameController *gamecontroller,
615 SDL_GameControllerAxis axis);
618 * Query whether a game controller has a given axis.
620 * This merely reports whether the controller's mapping defined this axis, as
621 * that is all the information SDL has about the physical device.
623 * \param gamecontroller a game controller
624 * \param axis an axis enum value (an SDL_GameControllerAxis value)
625 * \returns SDL_TRUE if the controller has this axis, SDL_FALSE otherwise.
627 * \since This function is available since SDL 2.0.14.
629 extern DECLSPEC SDL_bool SDLCALL
630 SDL_GameControllerHasAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis);
633 * Get the current state of an axis control on a game controller.
635 * The axis indices start at index 0.
637 * The state is a value ranging from -32768 to 32767. Triggers, however, range
638 * from 0 to 32767 (they never return a negative value).
640 * \param gamecontroller a game controller
641 * \param axis an axis index (one of the SDL_GameControllerAxis values)
642 * \returns axis state (including 0) on success or 0 (also) on failure; call
643 * SDL_GetError() for more information.
645 * \since This function is available since SDL 2.0.0.
647 * \sa SDL_GameControllerGetButton
649 extern DECLSPEC Sint16 SDLCALL
650 SDL_GameControllerGetAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis);
653 * The list of buttons available from a controller
657 SDL_CONTROLLER_BUTTON_INVALID = -1,
658 SDL_CONTROLLER_BUTTON_A,
659 SDL_CONTROLLER_BUTTON_B,
660 SDL_CONTROLLER_BUTTON_X,
661 SDL_CONTROLLER_BUTTON_Y,
662 SDL_CONTROLLER_BUTTON_BACK,
663 SDL_CONTROLLER_BUTTON_GUIDE,
664 SDL_CONTROLLER_BUTTON_START,
665 SDL_CONTROLLER_BUTTON_LEFTSTICK,
666 SDL_CONTROLLER_BUTTON_RIGHTSTICK,
667 SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
668 SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
669 SDL_CONTROLLER_BUTTON_DPAD_UP,
670 SDL_CONTROLLER_BUTTON_DPAD_DOWN,
671 SDL_CONTROLLER_BUTTON_DPAD_LEFT,
672 SDL_CONTROLLER_BUTTON_DPAD_RIGHT,
673 SDL_CONTROLLER_BUTTON_MISC1, /* Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Amazon Luna microphone button */
674 SDL_CONTROLLER_BUTTON_PADDLE1, /* Xbox Elite paddle P1 */
675 SDL_CONTROLLER_BUTTON_PADDLE2, /* Xbox Elite paddle P3 */
676 SDL_CONTROLLER_BUTTON_PADDLE3, /* Xbox Elite paddle P2 */
677 SDL_CONTROLLER_BUTTON_PADDLE4, /* Xbox Elite paddle P4 */
678 SDL_CONTROLLER_BUTTON_TOUCHPAD, /* PS4/PS5 touchpad button */
679 SDL_CONTROLLER_BUTTON_MAX
680 } SDL_GameControllerButton;
683 * Convert a string into an SDL_GameControllerButton enum.
685 * This function is called internally to translate SDL_GameController mapping
686 * strings for the underlying joystick device into the consistent
687 * SDL_GameController mapping. You do not normally need to call this function
688 * unless you are parsing SDL_GameController mappings in your own code.
690 * \param str string representing a SDL_GameController axis
691 * \returns the SDL_GameControllerButton enum corresponding to the input
692 * string, or `SDL_CONTROLLER_AXIS_INVALID` if no match was found.
694 * \since This function is available since SDL 2.0.0.
696 extern DECLSPEC SDL_GameControllerButton SDLCALL SDL_GameControllerGetButtonFromString(const char *str);
699 * Convert from an SDL_GameControllerButton enum to a string.
701 * The caller should not SDL_free() the returned string.
703 * \param button an enum value for a given SDL_GameControllerButton
704 * \returns a string for the given button, or NULL if an invalid axis is
705 * specified. The string returned is of the format used by
706 * SDL_GameController mapping strings.
708 * \since This function is available since SDL 2.0.0.
710 * \sa SDL_GameControllerGetButtonFromString
712 extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForButton(SDL_GameControllerButton button);
715 * Get the SDL joystick layer binding for a controller button mapping.
717 * \param gamecontroller a game controller
718 * \param button an button enum value (an SDL_GameControllerButton value)
719 * \returns a SDL_GameControllerButtonBind describing the bind. On failure
720 * (like the given Controller button doesn't exist on the device),
721 * its `.bindType` will be `SDL_CONTROLLER_BINDTYPE_NONE`.
723 * \since This function is available since SDL 2.0.0.
725 * \sa SDL_GameControllerGetBindForAxis
727 extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
728 SDL_GameControllerGetBindForButton(SDL_GameController *gamecontroller,
729 SDL_GameControllerButton button);
732 * Query whether a game controller has a given button.
734 * This merely reports whether the controller's mapping defined this button,
735 * as that is all the information SDL has about the physical device.
737 * \param gamecontroller a game controller
738 * \param button a button enum value (an SDL_GameControllerButton value)
739 * \returns SDL_TRUE if the controller has this button, SDL_FALSE otherwise.
741 * \since This function is available since SDL 2.0.14.
743 extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasButton(SDL_GameController *gamecontroller,
744 SDL_GameControllerButton button);
747 * Get the current state of a button on a game controller.
749 * \param gamecontroller a game controller
750 * \param button a button index (one of the SDL_GameControllerButton values)
751 * \returns 1 for pressed state or 0 for not pressed state or error; call
752 * SDL_GetError() for more information.
754 * \since This function is available since SDL 2.0.0.
756 * \sa SDL_GameControllerGetAxis
758 extern DECLSPEC Uint8 SDLCALL SDL_GameControllerGetButton(SDL_GameController *gamecontroller,
759 SDL_GameControllerButton button);
762 * Get the number of touchpads on a game controller.
764 * \since This function is available since SDL 2.0.14.
766 extern DECLSPEC int SDLCALL SDL_GameControllerGetNumTouchpads(SDL_GameController *gamecontroller);
769 * Get the number of supported simultaneous fingers on a touchpad on a game
772 * \since This function is available since SDL 2.0.14.
774 extern DECLSPEC int SDLCALL SDL_GameControllerGetNumTouchpadFingers(SDL_GameController *gamecontroller, int touchpad);
777 * Get the current state of a finger on a touchpad on a game controller.
779 * \since This function is available since SDL 2.0.14.
781 extern DECLSPEC int SDLCALL SDL_GameControllerGetTouchpadFinger(SDL_GameController *gamecontroller, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure);
784 * Return whether a game controller has a particular sensor.
786 * \param gamecontroller The controller to query
787 * \param type The type of sensor to query
788 * \returns SDL_TRUE if the sensor exists, SDL_FALSE otherwise.
790 * \since This function is available since SDL 2.0.14.
792 extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasSensor(SDL_GameController *gamecontroller, SDL_SensorType type);
795 * Set whether data reporting for a game controller sensor is enabled.
797 * \param gamecontroller The controller to update
798 * \param type The type of sensor to enable/disable
799 * \param enabled Whether data reporting should be enabled
800 * \returns 0 or -1 if an error occurred.
802 * \since This function is available since SDL 2.0.14.
804 extern DECLSPEC int SDLCALL SDL_GameControllerSetSensorEnabled(SDL_GameController *gamecontroller, SDL_SensorType type, SDL_bool enabled);
807 * Query whether sensor data reporting is enabled for a game controller.
809 * \param gamecontroller The controller to query
810 * \param type The type of sensor to query
811 * \returns SDL_TRUE if the sensor is enabled, SDL_FALSE otherwise.
813 * \since This function is available since SDL 2.0.14.
815 extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerIsSensorEnabled(SDL_GameController *gamecontroller, SDL_SensorType type);
818 * Get the data rate (number of events per second) of a game controller
821 * \param gamecontroller The controller to query
822 * \param type The type of sensor to query
823 * \return the data rate, or 0.0f if the data rate is not available.
825 * \since This function is available since SDL 2.0.16.
827 extern DECLSPEC float SDLCALL SDL_GameControllerGetSensorDataRate(SDL_GameController *gamecontroller, SDL_SensorType type);
830 * Get the current state of a game controller sensor.
832 * The number of values and interpretation of the data is sensor dependent.
833 * See SDL_sensor.h for the details for each type of sensor.
835 * \param gamecontroller The controller to query
836 * \param type The type of sensor to query
837 * \param data A pointer filled with the current sensor state
838 * \param num_values The number of values to write to data
839 * \return 0 or -1 if an error occurred.
841 * \since This function is available since SDL 2.0.14.
843 extern DECLSPEC int SDLCALL SDL_GameControllerGetSensorData(SDL_GameController *gamecontroller, SDL_SensorType type, float *data, int num_values);
846 * Start a rumble effect on a game controller.
848 * Each call to this function cancels any previous rumble effect, and calling
849 * it with 0 intensity stops any rumbling.
851 * \param gamecontroller The controller to vibrate
852 * \param low_frequency_rumble The intensity of the low frequency (left)
853 * rumble motor, from 0 to 0xFFFF
854 * \param high_frequency_rumble The intensity of the high frequency (right)
855 * rumble motor, from 0 to 0xFFFF
856 * \param duration_ms The duration of the rumble effect, in milliseconds
857 * \returns 0, or -1 if rumble isn't supported on this controller
859 * \since This function is available since SDL 2.0.9.
861 * \sa SDL_GameControllerHasRumble
863 extern DECLSPEC int SDLCALL SDL_GameControllerRumble(SDL_GameController *gamecontroller, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
866 * Start a rumble effect in the game controller's triggers.
868 * Each call to this function cancels any previous trigger rumble effect, and
869 * calling it with 0 intensity stops any rumbling.
871 * Note that this is rumbling of the _triggers_ and not the game controller as
872 * a whole. This is currently only supported on Xbox One controllers. If you
873 * want the (more common) whole-controller rumble, use
874 * SDL_GameControllerRumble() instead.
876 * \param gamecontroller The controller to vibrate
877 * \param left_rumble The intensity of the left trigger rumble motor, from 0
879 * \param right_rumble The intensity of the right trigger rumble motor, from 0
881 * \param duration_ms The duration of the rumble effect, in milliseconds
882 * \returns 0, or -1 if trigger rumble isn't supported on this controller
884 * \since This function is available since SDL 2.0.14.
886 * \sa SDL_GameControllerHasRumbleTriggers
888 extern DECLSPEC int SDLCALL SDL_GameControllerRumbleTriggers(SDL_GameController *gamecontroller, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
891 * Query whether a game controller has an LED.
893 * \param gamecontroller The controller to query
894 * \returns SDL_TRUE, or SDL_FALSE if this controller does not have a
897 * \since This function is available since SDL 2.0.14.
899 extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasLED(SDL_GameController *gamecontroller);
902 * Query whether a game controller has rumble support.
904 * \param gamecontroller The controller to query
905 * \returns SDL_TRUE, or SDL_FALSE if this controller does not have rumble
908 * \since This function is available since SDL 2.0.18.
910 * \sa SDL_GameControllerRumble
912 extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasRumble(SDL_GameController *gamecontroller);
915 * Query whether a game controller has rumble support on triggers.
917 * \param gamecontroller The controller to query
918 * \returns SDL_TRUE, or SDL_FALSE if this controller does not have trigger
921 * \since This function is available since SDL 2.0.18.
923 * \sa SDL_GameControllerRumbleTriggers
925 extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasRumbleTriggers(SDL_GameController *gamecontroller);
928 * Update a game controller's LED color.
930 * \param gamecontroller The controller to update
931 * \param red The intensity of the red LED
932 * \param green The intensity of the green LED
933 * \param blue The intensity of the blue LED
934 * \returns 0, or -1 if this controller does not have a modifiable LED
936 * \since This function is available since SDL 2.0.14.
938 extern DECLSPEC int SDLCALL SDL_GameControllerSetLED(SDL_GameController *gamecontroller, Uint8 red, Uint8 green, Uint8 blue);
941 * Send a controller specific effect packet
943 * \param gamecontroller The controller to affect
944 * \param data The data to send to the controller
945 * \param size The size of the data to send to the controller
946 * \returns 0, or -1 if this controller or driver doesn't support effect
949 * \since This function is available since SDL 2.0.16.
951 extern DECLSPEC int SDLCALL SDL_GameControllerSendEffect(SDL_GameController *gamecontroller, const void *data, int size);
954 * Close a game controller previously opened with SDL_GameControllerOpen().
956 * \param gamecontroller a game controller identifier previously returned by
957 * SDL_GameControllerOpen()
959 * \since This function is available since SDL 2.0.0.
961 * \sa SDL_GameControllerOpen
963 extern DECLSPEC void SDLCALL SDL_GameControllerClose(SDL_GameController *gamecontroller);
966 * Return the sfSymbolsName for a given button on a game controller on Apple
969 * \param gamecontroller the controller to query
970 * \param button a button on the game controller
971 * \returns the sfSymbolsName or NULL if the name can't be found
973 * \since This function is available since SDL 2.0.18.
975 * \sa SDL_GameControllerGetAppleSFSymbolsNameForAxis
977 extern DECLSPEC const char* SDLCALL SDL_GameControllerGetAppleSFSymbolsNameForButton(SDL_GameController *gamecontroller, SDL_GameControllerButton button);
980 * Return the sfSymbolsName for a given axis on a game controller on Apple
983 * \param gamecontroller the controller to query
984 * \param axis an axis on the game controller
985 * \returns the sfSymbolsName or NULL if the name can't be found
987 * \since This function is available since SDL 2.0.18.
989 * \sa SDL_GameControllerGetAppleSFSymbolsNameForButton
991 extern DECLSPEC const char* SDLCALL SDL_GameControllerGetAppleSFSymbolsNameForAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis);
994 /* Ends C function definitions when using C++ */
998 #include "close_code.h"
1000 #endif /* SDL_gamecontroller_h_ */
1002 /* vi: set ts=4 sw=4 expandtab: */