SDL 3.0
SDL_gamepad.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2024 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_gamepad.h
24 *
25 * Include file for SDL gamepad event handling
26 */
27
28#ifndef SDL_gamepad_h_
29#define SDL_gamepad_h_
30
31#include <SDL3/SDL_stdinc.h>
32#include <SDL3/SDL_error.h>
33#include <SDL3/SDL_joystick.h>
34#include <SDL3/SDL_properties.h>
35#include <SDL3/SDL_iostream.h>
36#include <SDL3/SDL_sensor.h>
37
38#include <SDL3/SDL_begin_code.h>
39/* Set up for C function definitions, even when using C++ */
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44/**
45 * \file SDL_gamepad.h
46 *
47 * In order to use these functions, SDL_Init() must have been called
48 * with the ::SDL_INIT_GAMEPAD flag. This causes SDL to scan the system
49 * for gamepads, and load appropriate drivers.
50 *
51 * If you would like to receive gamepad updates while the application
52 * is in the background, you should set the following hint before calling
53 * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
54 */
55
56/**
57 * The structure used to identify an SDL gamepad
58 */
59struct SDL_Gamepad;
60typedef struct SDL_Gamepad SDL_Gamepad;
61
77
78/**
79 * The list of buttons available on a gamepad
80 *
81 * For controllers that use a diamond pattern for the face buttons,
82 * the south/east/west/north buttons below correspond to the locations
83 * in the diamond pattern. For Xbox controllers, this would be A/B/X/Y,
84 * for Nintendo Switch controllers, this would be B/A/Y/X, for
85 * PlayStation controllers this would be Cross/Circle/Square/Triangle.
86 *
87 * For controllers that don't use a diamond pattern for the face buttons,
88 * the south/east/west/north buttons indicate the buttons labeled A, B,
89 * C, D, or 1, 2, 3, 4, or for controllers that aren't labeled, they are
90 * the primary, secondary, etc. buttons.
91 *
92 * The activate action is often the south button and the cancel action
93 * is often the east button, but in some regions this is reversed, so
94 * your game should allow remapping actions based on user preferences.
95 *
96 * You can query the labels for the face buttons using SDL_GetGamepadButtonLabel()
97 */
98typedef enum
99{
101 SDL_GAMEPAD_BUTTON_SOUTH, /* Bottom face button (e.g. Xbox A button) */
102 SDL_GAMEPAD_BUTTON_EAST, /* Right face button (e.g. Xbox B button) */
103 SDL_GAMEPAD_BUTTON_WEST, /* Left face button (e.g. Xbox X button) */
104 SDL_GAMEPAD_BUTTON_NORTH, /* Top face button (e.g. Xbox Y button) */
116 SDL_GAMEPAD_BUTTON_MISC1, /* Additional button (e.g. Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Amazon Luna microphone button, Google Stadia capture button) */
117 SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1, /* Upper or primary paddle, under your right hand (e.g. Xbox Elite paddle P1) */
118 SDL_GAMEPAD_BUTTON_LEFT_PADDLE1, /* Upper or primary paddle, under your left hand (e.g. Xbox Elite paddle P3) */
119 SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2, /* Lower or secondary paddle, under your right hand (e.g. Xbox Elite paddle P2) */
120 SDL_GAMEPAD_BUTTON_LEFT_PADDLE2, /* Lower or secondary paddle, under your left hand (e.g. Xbox Elite paddle P4) */
121 SDL_GAMEPAD_BUTTON_TOUCHPAD, /* PS4/PS5 touchpad button */
122 SDL_GAMEPAD_BUTTON_MISC2, /* Additional button */
123 SDL_GAMEPAD_BUTTON_MISC3, /* Additional button */
124 SDL_GAMEPAD_BUTTON_MISC4, /* Additional button */
125 SDL_GAMEPAD_BUTTON_MISC5, /* Additional button */
126 SDL_GAMEPAD_BUTTON_MISC6, /* Additional button */
129
130/**
131 * The set of gamepad button labels
132 *
133 * This isn't a complete set, just the face buttons to make it easy to show button prompts.
134 *
135 * For a complete set, you should look at the button and gamepad type and have a set of symbols that work well with your art style.
136 */
149
150/**
151 * The list of axes available on a gamepad
152 *
153 * Thumbstick axis values range from SDL_JOYSTICK_AXIS_MIN to SDL_JOYSTICK_AXIS_MAX,
154 * and are centered within ~8000 of zero, though advanced UI will allow users to set
155 * or autodetect the dead zone, which varies between gamepads.
156 *
157 * Trigger axis values range from 0 (released) to SDL_JOYSTICK_AXIS_MAX
158 * (fully pressed) when reported by SDL_GetGamepadAxis(). Note that this is not the
159 * same range that will be reported by the lower-level SDL_GetJoystickAxis().
160 */
172
180
181typedef struct SDL_GamepadBinding
182{
184 union
185 {
187
188 struct
189 {
190 int axis;
194
195 struct
196 {
197 int hat;
200
202
204 union
205 {
207
208 struct
209 {
211 int axis_min;
212 int axis_max;
214
216
218
219
220/**
221 * Add support for gamepads that SDL is unaware of or change the binding of an
222 * existing gamepad.
223 *
224 * The mapping string has the format "GUID,name,mapping", where GUID is the
225 * string value from SDL_GetJoystickGUIDString(), name is the human readable
226 * string for the device and mappings are gamepad mappings to joystick ones.
227 * Under Windows there is a reserved GUID of "xinput" that covers all XInput
228 * devices. The mapping format for joystick is:
229 *
230 * - `bX`: a joystick button, index X
231 * - `hX.Y`: hat X with value Y
232 * - `aX`: axis X of the joystick
233 *
234 * Buttons can be used as a gamepad axes and vice versa.
235 *
236 * This string shows an example of a valid mapping for a gamepad:
237 *
238 * ```c
239 * "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"
240 * ```
241 *
242 * \param mapping the mapping string
243 * \returns 1 if a new mapping is added, 0 if an existing mapping is updated,
244 * -1 on error; call SDL_GetError() for more information.
245 *
246 * \since This function is available since SDL 3.0.0.
247 *
248 * \sa SDL_GetGamepadMapping
249 * \sa SDL_GetGamepadMappingForGUID
250 */
251extern DECLSPEC int SDLCALL SDL_AddGamepadMapping(const char *mapping);
252
253/**
254 * Load a set of gamepad mappings from an SDL_IOStream.
255 *
256 * You can call this function several times, if needed, to load different
257 * database files.
258 *
259 * If a new mapping is loaded for an already known gamepad GUID, the later
260 * version will overwrite the one currently loaded.
261 *
262 * Mappings not belonging to the current platform or with no platform field
263 * specified will be ignored (i.e. mappings for Linux will be ignored in
264 * Windows, etc).
265 *
266 * This function will load the text database entirely in memory before
267 * processing it, so take this into consideration if you are in a memory
268 * constrained environment.
269 *
270 * \param src the data stream for the mappings to be added
271 * \param closeio if SDL_TRUE, calls SDL_CloseIO() on `src` before returning,
272 * even in the case of an error
273 * \returns the number of mappings added or -1 on error; call SDL_GetError()
274 * for more information.
275 *
276 * \since This function is available since SDL 3.0.0.
277 *
278 * \sa SDL_AddGamepadMapping
279 * \sa SDL_AddGamepadMappingsFromFile
280 * \sa SDL_GetGamepadMapping
281 * \sa SDL_GetGamepadMappingForGUID
282 */
283extern DECLSPEC int SDLCALL SDL_AddGamepadMappingsFromIO(SDL_IOStream *src, SDL_bool closeio);
284
285/**
286 * Load a set of gamepad mappings from a file.
287 *
288 * You can call this function several times, if needed, to load different
289 * database files.
290 *
291 * If a new mapping is loaded for an already known gamepad GUID, the later
292 * version will overwrite the one currently loaded.
293 *
294 * Mappings not belonging to the current platform or with no platform field
295 * specified will be ignored (i.e. mappings for Linux will be ignored in
296 * Windows, etc).
297 *
298 * \param file the mappings file to load
299 * \returns the number of mappings added or -1 on error; call SDL_GetError()
300 * for more information.
301 *
302 * \since This function is available since SDL 3.0.0.
303 *
304 * \sa SDL_AddGamepadMapping
305 * \sa SDL_AddGamepadMappingsFromIO
306 * \sa SDL_GetGamepadMapping
307 * \sa SDL_GetGamepadMappingForGUID
308 */
309extern DECLSPEC int SDLCALL SDL_AddGamepadMappingsFromFile(const char *file);
310
311/**
312 * Reinitialize the SDL mapping database to its initial state.
313 *
314 * This will generate gamepad events as needed if device mappings change.
315 *
316 * \returns 0 on success or a negative error code on failure; call
317 * SDL_GetError() for more information.
318 *
319 * \since This function is available since SDL 3.0.0.
320 */
321extern DECLSPEC int SDLCALL SDL_ReloadGamepadMappings(void);
322
323/**
324 * Get the current gamepad mappings.
325 *
326 * You must free the returned pointer with SDL_free() when you are done with
327 * it, but you do _not_ free each string in the array.
328 *
329 * \param count a pointer filled in with the number of mappings returned, can
330 * be NULL.
331 * \returns an array of the mapping strings, NULL-terminated. Must be freed
332 * with SDL_free(). Returns NULL on error.
333 *
334 * \since This function is available since SDL 3.0.0.
335 */
336extern DECLSPEC char ** SDLCALL SDL_GetGamepadMappings(int *count);
337
338/**
339 * Get the gamepad mapping string for a given GUID.
340 *
341 * The returned string must be freed with SDL_free().
342 *
343 * \param guid a structure containing the GUID for which a mapping is desired
344 * \returns a mapping string or NULL on error; call SDL_GetError() for more
345 * information.
346 *
347 * \since This function is available since SDL 3.0.0.
348 *
349 * \sa SDL_GetJoystickInstanceGUID
350 * \sa SDL_GetJoystickGUID
351 */
352extern DECLSPEC char * SDLCALL SDL_GetGamepadMappingForGUID(SDL_JoystickGUID guid);
353
354/**
355 * Get the current mapping of a gamepad.
356 *
357 * The returned string must be freed with SDL_free().
358 *
359 * Details about mappings are discussed with SDL_AddGamepadMapping().
360 *
361 * \param gamepad the gamepad you want to get the current mapping for
362 * \returns a string that has the gamepad's mapping or NULL if no mapping is
363 * available; call SDL_GetError() for more information.
364 *
365 * \since This function is available since SDL 3.0.0.
366 *
367 * \sa SDL_AddGamepadMapping
368 * \sa SDL_GetGamepadInstanceMapping
369 * \sa SDL_GetGamepadMappingForGUID
370 * \sa SDL_SetGamepadMapping
371 */
372extern DECLSPEC char * SDLCALL SDL_GetGamepadMapping(SDL_Gamepad *gamepad);
373
374/**
375 * Set the current mapping of a joystick or gamepad.
376 *
377 * Details about mappings are discussed with SDL_AddGamepadMapping().
378 *
379 * \param instance_id the joystick instance ID
380 * \param mapping the mapping to use for this device, or NULL to clear the
381 * mapping
382 * \returns 0 on success or a negative error code on failure; call
383 * SDL_GetError() for more information.
384 *
385 * \since This function is available since SDL 3.0.0.
386 *
387 * \sa SDL_AddGamepadMapping
388 * \sa SDL_GetGamepadMapping
389 */
390extern DECLSPEC int SDLCALL SDL_SetGamepadMapping(SDL_JoystickID instance_id, const char *mapping);
391
392/**
393 * Return whether a gamepad is currently connected.
394 *
395 * \returns SDL_TRUE if a gamepad is connected, SDL_FALSE otherwise.
396 *
397 * \since This function is available since SDL 3.0.0.
398 *
399 * \sa SDL_GetGamepads
400 */
401extern DECLSPEC SDL_bool SDLCALL SDL_HasGamepad(void);
402
403/**
404 * Get a list of currently connected gamepads.
405 *
406 * \param count a pointer filled in with the number of gamepads returned
407 * \returns a 0 terminated array of joystick instance IDs which should be
408 * freed with SDL_free(), or NULL on error; call SDL_GetError() for
409 * more details.
410 *
411 * \since This function is available since SDL 3.0.0.
412 *
413 * \sa SDL_HasGamepad
414 * \sa SDL_OpenGamepad
415 */
416extern DECLSPEC SDL_JoystickID *SDLCALL SDL_GetGamepads(int *count);
417
418/**
419 * Check if the given joystick is supported by the gamepad interface.
420 *
421 * \param instance_id the joystick instance ID
422 * \returns SDL_TRUE if the given joystick is supported by the gamepad
423 * interface, SDL_FALSE if it isn't or it's an invalid index.
424 *
425 * \since This function is available since SDL 3.0.0.
426 *
427 * \sa SDL_GetJoysticks
428 * \sa SDL_OpenGamepad
429 */
430extern DECLSPEC SDL_bool SDLCALL SDL_IsGamepad(SDL_JoystickID instance_id);
431
432/**
433 * Get the implementation dependent name of a gamepad.
434 *
435 * This can be called before any gamepads are opened.
436 *
437 * \param instance_id the joystick instance ID
438 * \returns the name of the selected gamepad. If no name can be found, this
439 * function returns NULL; call SDL_GetError() for more information.
440 *
441 * \since This function is available since SDL 3.0.0.
442 *
443 * \sa SDL_GetGamepadName
444 * \sa SDL_GetGamepads
445 */
446extern DECLSPEC const char *SDLCALL SDL_GetGamepadInstanceName(SDL_JoystickID instance_id);
447
448/**
449 * Get the implementation dependent path of a gamepad.
450 *
451 * This can be called before any gamepads are opened.
452 *
453 * \param instance_id the joystick instance ID
454 * \returns the path of the selected gamepad. If no path can be found, this
455 * function returns NULL; call SDL_GetError() for more information.
456 *
457 * \since This function is available since SDL 3.0.0.
458 *
459 * \sa SDL_GetGamepadPath
460 * \sa SDL_GetGamepads
461 */
462extern DECLSPEC const char *SDLCALL SDL_GetGamepadInstancePath(SDL_JoystickID instance_id);
463
464/**
465 * Get the player index of a gamepad.
466 *
467 * This can be called before any gamepads are opened.
468 *
469 * \param instance_id the joystick instance ID
470 * \returns the player index of a gamepad, or -1 if it's not available
471 *
472 * \since This function is available since SDL 3.0.0.
473 *
474 * \sa SDL_GetGamepadPlayerIndex
475 * \sa SDL_GetGamepads
476 */
477extern DECLSPEC int SDLCALL SDL_GetGamepadInstancePlayerIndex(SDL_JoystickID instance_id);
478
479/**
480 * Get the implementation-dependent GUID of a gamepad.
481 *
482 * This can be called before any gamepads are opened.
483 *
484 * \param instance_id the joystick instance ID
485 * \returns the GUID of the selected gamepad. If called on an invalid index,
486 * this function returns a zero GUID
487 *
488 * \since This function is available since SDL 3.0.0.
489 *
490 * \sa SDL_GetGamepadGUID
491 * \sa SDL_GetGamepadGUIDString
492 * \sa SDL_GetGamepads
493 */
494extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_GetGamepadInstanceGUID(SDL_JoystickID instance_id);
495
496/**
497 * Get the USB vendor ID of a gamepad, if available.
498 *
499 * This can be called before any gamepads are opened. If the vendor ID isn't
500 * available this function returns 0.
501 *
502 * \param instance_id the joystick instance ID
503 * \returns the USB vendor ID of the selected gamepad. If called on an invalid
504 * index, this function returns zero
505 *
506 * \since This function is available since SDL 3.0.0.
507 *
508 * \sa SDL_GetGamepadVendor
509 * \sa SDL_GetGamepads
510 */
511extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadInstanceVendor(SDL_JoystickID instance_id);
512
513/**
514 * Get the USB product ID of a gamepad, if available.
515 *
516 * This can be called before any gamepads are opened. If the product ID isn't
517 * available this function returns 0.
518 *
519 * \param instance_id the joystick instance ID
520 * \returns the USB product ID of the selected gamepad. If called on an
521 * invalid index, this function returns zero
522 *
523 * \since This function is available since SDL 3.0.0.
524 *
525 * \sa SDL_GetGamepadProduct
526 * \sa SDL_GetGamepads
527 */
528extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadInstanceProduct(SDL_JoystickID instance_id);
529
530/**
531 * Get the product version of a gamepad, if available.
532 *
533 * This can be called before any gamepads are opened. If the product version
534 * isn't available this function returns 0.
535 *
536 * \param instance_id the joystick instance ID
537 * \returns the product version of the selected gamepad. If called on an
538 * invalid index, this function returns zero
539 *
540 * \since This function is available since SDL 3.0.0.
541 *
542 * \sa SDL_GetGamepadProductVersion
543 * \sa SDL_GetGamepads
544 */
545extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadInstanceProductVersion(SDL_JoystickID instance_id);
546
547/**
548 * Get the type of a gamepad.
549 *
550 * This can be called before any gamepads are opened.
551 *
552 * \param instance_id the joystick instance ID
553 * \returns the gamepad type.
554 *
555 * \since This function is available since SDL 3.0.0.
556 *
557 * \sa SDL_GetGamepadType
558 * \sa SDL_GetGamepads
559 * \sa SDL_GetRealGamepadInstanceType
560 */
561extern DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadInstanceType(SDL_JoystickID instance_id);
562
563/**
564 * Get the type of a gamepad, ignoring any mapping override.
565 *
566 * This can be called before any gamepads are opened.
567 *
568 * \param instance_id the joystick instance ID
569 * \returns the gamepad type.
570 *
571 * \since This function is available since SDL 3.0.0.
572 *
573 * \sa SDL_GetGamepadInstanceType
574 * \sa SDL_GetGamepads
575 * \sa SDL_GetRealGamepadType
576 */
578
579/**
580 * Get the mapping of a gamepad.
581 *
582 * This can be called before any gamepads are opened.
583 *
584 * \param instance_id the joystick instance ID
585 * \returns the mapping string. Must be freed with SDL_free(). Returns NULL if
586 * no mapping is available.
587 *
588 * \since This function is available since SDL 3.0.0.
589 *
590 * \sa SDL_GetGamepads
591 * \sa SDL_GetGamepadMapping
592 */
593extern DECLSPEC char *SDLCALL SDL_GetGamepadInstanceMapping(SDL_JoystickID instance_id);
594
595/**
596 * Open a gamepad for use.
597 *
598 * \param instance_id the joystick instance ID
599 * \returns a gamepad identifier or NULL if an error occurred; call
600 * SDL_GetError() for more information.
601 *
602 * \since This function is available since SDL 3.0.0.
603 *
604 * \sa SDL_CloseGamepad
605 * \sa SDL_IsGamepad
606 */
607extern DECLSPEC SDL_Gamepad *SDLCALL SDL_OpenGamepad(SDL_JoystickID instance_id);
608
609/**
610 * Get the SDL_Gamepad associated with a joystick instance ID, if it has been
611 * opened.
612 *
613 * \param instance_id the joystick instance ID of the gamepad
614 * \returns an SDL_Gamepad on success or NULL on failure or if it hasn't been
615 * opened yet; call SDL_GetError() for more information.
616 *
617 * \since This function is available since SDL 3.0.0.
618 */
619extern DECLSPEC SDL_Gamepad *SDLCALL SDL_GetGamepadFromInstanceID(SDL_JoystickID instance_id);
620
621/**
622 * Get the SDL_Gamepad associated with a player index.
623 *
624 * \param player_index the player index, which different from the instance ID
625 * \returns the SDL_Gamepad associated with a player index.
626 *
627 * \since This function is available since SDL 3.0.0.
628 *
629 * \sa SDL_GetGamepadPlayerIndex
630 * \sa SDL_SetGamepadPlayerIndex
631 */
632extern DECLSPEC SDL_Gamepad *SDLCALL SDL_GetGamepadFromPlayerIndex(int player_index);
633
634/**
635 * Get the properties associated with an opened gamepad.
636 *
637 * These properties are shared with the underlying joystick object.
638 *
639 * The following read-only properties are provided by SDL:
640 *
641 * - `SDL_PROP_GAMEPAD_CAP_MONO_LED_BOOLEAN`: true if this gamepad has an LED
642 * that has adjustable brightness
643 * - `SDL_PROP_GAMEPAD_CAP_RGB_LED_BOOLEAN`: true if this gamepad has an LED
644 * that has adjustable color
645 * - `SDL_PROP_GAMEPAD_CAP_PLAYER_LED_BOOLEAN`: true if this gamepad has a
646 * player LED
647 * - `SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN`: true if this gamepad has
648 * left/right rumble
649 * - `SDL_PROP_GAMEPAD_CAP_TRIGGER_RUMBLE_BOOLEAN`: true if this gamepad has
650 * simple trigger rumble
651 *
652 * \param gamepad a gamepad identifier previously returned by
653 * SDL_OpenGamepad()
654 * \returns a valid property ID on success or 0 on failure; call
655 * SDL_GetError() for more information.
656 *
657 * \since This function is available since SDL 3.0.0.
658 *
659 * \sa SDL_GetProperty
660 * \sa SDL_SetProperty
661 */
662extern DECLSPEC SDL_PropertiesID SDLCALL SDL_GetGamepadProperties(SDL_Gamepad *gamepad);
663
664#define SDL_PROP_GAMEPAD_CAP_MONO_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN
665#define SDL_PROP_GAMEPAD_CAP_RGB_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN
666#define SDL_PROP_GAMEPAD_CAP_PLAYER_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN
667#define SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN
668#define SDL_PROP_GAMEPAD_CAP_TRIGGER_RUMBLE_BOOLEAN SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN
669
670/**
671 * Get the instance ID of an opened gamepad.
672 *
673 * \param gamepad a gamepad identifier previously returned by
674 * SDL_OpenGamepad()
675 * \returns the instance ID of the specified gamepad on success or 0 on
676 * failure; call SDL_GetError() for more information.
677 *
678 * \since This function is available since SDL 3.0.0.
679 */
680extern DECLSPEC SDL_JoystickID SDLCALL SDL_GetGamepadInstanceID(SDL_Gamepad *gamepad);
681
682/**
683 * Get the implementation-dependent name for an opened gamepad.
684 *
685 * \param gamepad a gamepad identifier previously returned by
686 * SDL_OpenGamepad()
687 * \returns the implementation dependent name for the gamepad, or NULL if
688 * there is no name or the identifier passed is invalid.
689 *
690 * \since This function is available since SDL 3.0.0.
691 *
692 * \sa SDL_GetGamepadInstanceName
693 */
694extern DECLSPEC const char *SDLCALL SDL_GetGamepadName(SDL_Gamepad *gamepad);
695
696/**
697 * Get the implementation-dependent path for an opened gamepad.
698 *
699 * \param gamepad a gamepad identifier previously returned by
700 * SDL_OpenGamepad()
701 * \returns the implementation dependent path for the gamepad, or NULL if
702 * there is no path or the identifier passed is invalid.
703 *
704 * \since This function is available since SDL 3.0.0.
705 *
706 * \sa SDL_GetGamepadInstancePath
707 */
708extern DECLSPEC const char *SDLCALL SDL_GetGamepadPath(SDL_Gamepad *gamepad);
709
710/**
711 * Get the type of an opened gamepad.
712 *
713 * \param gamepad the gamepad object to query.
714 * \returns the gamepad type, or SDL_GAMEPAD_TYPE_UNKNOWN if it's not
715 * available.
716 *
717 * \since This function is available since SDL 3.0.0.
718 *
719 * \sa SDL_GetGamepadInstanceType
720 */
721extern DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadType(SDL_Gamepad *gamepad);
722
723/**
724 * Get the type of an opened gamepad, ignoring any mapping override.
725 *
726 * \param gamepad the gamepad object to query.
727 * \returns the gamepad type, or SDL_GAMEPAD_TYPE_UNKNOWN if it's not
728 * available.
729 *
730 * \since This function is available since SDL 3.0.0.
731 *
732 * \sa SDL_GetRealGamepadInstanceType
733 */
734extern DECLSPEC SDL_GamepadType SDLCALL SDL_GetRealGamepadType(SDL_Gamepad *gamepad);
735
736/**
737 * Get the player index of an opened gamepad.
738 *
739 * For XInput gamepads this returns the XInput user index.
740 *
741 * \param gamepad the gamepad object to query.
742 * \returns the player index for gamepad, or -1 if it's not available.
743 *
744 * \since This function is available since SDL 3.0.0.
745 *
746 * \sa SDL_SetGamepadPlayerIndex
747 */
748extern DECLSPEC int SDLCALL SDL_GetGamepadPlayerIndex(SDL_Gamepad *gamepad);
749
750/**
751 * Set the player index of an opened gamepad.
752 *
753 * \param gamepad the gamepad object to adjust.
754 * \param player_index Player index to assign to this gamepad, or -1 to clear
755 * the player index and turn off player LEDs.
756 * \returns 0 on success or a negative error code on failure; call
757 * SDL_GetError() for more information.
758 *
759 * \since This function is available since SDL 3.0.0.
760 *
761 * \sa SDL_GetGamepadPlayerIndex
762 */
763extern DECLSPEC int SDLCALL SDL_SetGamepadPlayerIndex(SDL_Gamepad *gamepad, int player_index);
764
765/**
766 * Get the USB vendor ID of an opened gamepad, if available.
767 *
768 * If the vendor ID isn't available this function returns 0.
769 *
770 * \param gamepad the gamepad object to query.
771 * \returns the USB vendor ID, or zero if unavailable.
772 *
773 * \since This function is available since SDL 3.0.0.
774 *
775 * \sa SDL_GetGamepadInstanceVendor
776 */
777extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadVendor(SDL_Gamepad *gamepad);
778
779/**
780 * Get the USB product ID of an opened gamepad, if available.
781 *
782 * If the product ID isn't available this function returns 0.
783 *
784 * \param gamepad the gamepad object to query.
785 * \returns the USB product ID, or zero if unavailable.
786 *
787 * \since This function is available since SDL 3.0.0.
788 *
789 * \sa SDL_GetGamepadInstanceProduct
790 */
791extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadProduct(SDL_Gamepad *gamepad);
792
793/**
794 * Get the product version of an opened gamepad, if available.
795 *
796 * If the product version isn't available this function returns 0.
797 *
798 * \param gamepad the gamepad object to query.
799 * \returns the USB product version, or zero if unavailable.
800 *
801 * \since This function is available since SDL 3.0.0.
802 *
803 * \sa SDL_GetGamepadInstanceProductVersion
804 */
805extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductVersion(SDL_Gamepad *gamepad);
806
807/**
808 * Get the firmware version of an opened gamepad, if available.
809 *
810 * If the firmware version isn't available this function returns 0.
811 *
812 * \param gamepad the gamepad object to query.
813 * \returns the gamepad firmware version, or zero if unavailable.
814 *
815 * \since This function is available since SDL 3.0.0.
816 */
817extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadFirmwareVersion(SDL_Gamepad *gamepad);
818
819/**
820 * Get the serial number of an opened gamepad, if available.
821 *
822 * Returns the serial number of the gamepad, or NULL if it is not available.
823 *
824 * \param gamepad the gamepad object to query.
825 * \returns the serial number, or NULL if unavailable.
826 *
827 * \since This function is available since SDL 3.0.0.
828 */
829extern DECLSPEC const char * SDLCALL SDL_GetGamepadSerial(SDL_Gamepad *gamepad);
830
831/**
832 * Get the Steam Input handle of an opened gamepad, if available.
833 *
834 * Returns an InputHandle_t for the gamepad that can be used with Steam Input
835 * API: https://partner.steamgames.com/doc/api/ISteamInput
836 *
837 * \param gamepad the gamepad object to query.
838 * \returns the gamepad handle, or 0 if unavailable.
839 *
840 * \since This function is available since SDL 3.0.0.
841 */
842extern DECLSPEC Uint64 SDLCALL SDL_GetGamepadSteamHandle(SDL_Gamepad *gamepad);
843
844/**
845 * Get the battery level of a gamepad, if available.
846 *
847 * \param gamepad a gamepad identifier previously returned by
848 * SDL_OpenGamepad()
849 * \returns the current battery level as SDL_JoystickPowerLevel on success or
850 * `SDL_JOYSTICK_POWER_UNKNOWN` if it is unknown
851 *
852 * \since This function is available since SDL 3.0.0.
853 */
855
856/**
857 * Check if a gamepad has been opened and is currently connected.
858 *
859 * \param gamepad a gamepad identifier previously returned by
860 * SDL_OpenGamepad()
861 * \returns SDL_TRUE if the gamepad has been opened and is currently
862 * connected, or SDL_FALSE if not.
863 *
864 * \since This function is available since SDL 3.0.0.
865 */
866extern DECLSPEC SDL_bool SDLCALL SDL_GamepadConnected(SDL_Gamepad *gamepad);
867
868/**
869 * Get the underlying joystick from a gamepad
870 *
871 * This function will give you a SDL_Joystick object, which allows you to use
872 * the SDL_Joystick functions with a SDL_Gamepad object. This would be useful
873 * for getting a joystick's position at any given time, even if it hasn't
874 * moved (moving it would produce an event, which would have the axis' value).
875 *
876 * The pointer returned is owned by the SDL_Gamepad. You should not call
877 * SDL_CloseJoystick() on it, for example, since doing so will likely cause
878 * SDL to crash.
879 *
880 * \param gamepad the gamepad object that you want to get a joystick from
881 * \returns an SDL_Joystick object; call SDL_GetError() for more information.
882 *
883 * \since This function is available since SDL 3.0.0.
884 */
885extern DECLSPEC SDL_Joystick *SDLCALL SDL_GetGamepadJoystick(SDL_Gamepad *gamepad);
886
887/**
888 * Set the state of gamepad event processing.
889 *
890 * If gamepad events are disabled, you must call SDL_UpdateGamepads() yourself
891 * and check the state of the gamepad when you want gamepad information.
892 *
893 * \param enabled whether to process gamepad events or not
894 *
895 * \since This function is available since SDL 3.0.0.
896 *
897 * \sa SDL_GamepadEventsEnabled
898 * \sa SDL_UpdateGamepads
899 */
900extern DECLSPEC void SDLCALL SDL_SetGamepadEventsEnabled(SDL_bool enabled);
901
902/**
903 * Query the state of gamepad event processing.
904 *
905 * If gamepad events are disabled, you must call SDL_UpdateGamepads() yourself
906 * and check the state of the gamepad when you want gamepad information.
907 *
908 * \returns SDL_TRUE if gamepad events are being processed, SDL_FALSE
909 * otherwise.
910 *
911 * \since This function is available since SDL 3.0.0.
912 *
913 * \sa SDL_SetGamepadEventsEnabled
914 */
915extern DECLSPEC SDL_bool SDLCALL SDL_GamepadEventsEnabled(void);
916
917/**
918 * Get the SDL joystick layer bindings for a gamepad
919 *
920 * \param gamepad a gamepad
921 * \param count a pointer filled in with the number of bindings returned
922 * \returns a NULL terminated array of pointers to bindings which should be
923 * freed with SDL_free(), or NULL on error; call SDL_GetError() for
924 * more details.
925 *
926 * \since This function is available since SDL 3.0.0.
927 */
928extern DECLSPEC SDL_GamepadBinding **SDLCALL SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count);
929
930/**
931 * Manually pump gamepad updates if not using the loop.
932 *
933 * This function is called automatically by the event loop if events are
934 * enabled. Under such circumstances, it will not be necessary to call this
935 * function.
936 *
937 * \since This function is available since SDL 3.0.0.
938 */
939extern DECLSPEC void SDLCALL SDL_UpdateGamepads(void);
940
941/**
942 * Convert a string into SDL_GamepadType enum.
943 *
944 * This function is called internally to translate SDL_Gamepad mapping strings
945 * for the underlying joystick device into the consistent SDL_Gamepad mapping.
946 * You do not normally need to call this function unless you are parsing
947 * SDL_Gamepad mappings in your own code.
948 *
949 * \param str string representing a SDL_GamepadType type
950 * \returns the SDL_GamepadType enum corresponding to the input string, or
951 * `SDL_GAMEPAD_TYPE_UNKNOWN` if no match was found.
952 *
953 * \since This function is available since SDL 3.0.0.
954 *
955 * \sa SDL_GetGamepadStringForType
956 */
957extern DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadTypeFromString(const char *str);
958
959/**
960 * Convert from an SDL_GamepadType enum to a string.
961 *
962 * The caller should not SDL_free() the returned string.
963 *
964 * \param type an enum value for a given SDL_GamepadType
965 * \returns a string for the given type, or NULL if an invalid type is
966 * specified. The string returned is of the format used by
967 * SDL_Gamepad mapping strings.
968 *
969 * \since This function is available since SDL 3.0.0.
970 *
971 * \sa SDL_GetGamepadTypeFromString
972 */
973extern DECLSPEC const char *SDLCALL SDL_GetGamepadStringForType(SDL_GamepadType type);
974
975/**
976 * Convert a string into SDL_GamepadAxis enum.
977 *
978 * This function is called internally to translate SDL_Gamepad mapping strings
979 * for the underlying joystick device into the consistent SDL_Gamepad mapping.
980 * You do not normally need to call this function unless you are parsing
981 * SDL_Gamepad mappings in your own code.
982 *
983 * Note specially that "righttrigger" and "lefttrigger" map to
984 * `SDL_GAMEPAD_AXIS_RIGHT_TRIGGER` and `SDL_GAMEPAD_AXIS_LEFT_TRIGGER`,
985 * respectively.
986 *
987 * \param str string representing a SDL_Gamepad axis
988 * \returns the SDL_GamepadAxis enum corresponding to the input string, or
989 * `SDL_GAMEPAD_AXIS_INVALID` if no match was found.
990 *
991 * \since This function is available since SDL 3.0.0.
992 *
993 * \sa SDL_GetGamepadStringForAxis
994 */
995extern DECLSPEC SDL_GamepadAxis SDLCALL SDL_GetGamepadAxisFromString(const char *str);
996
997/**
998 * Convert from an SDL_GamepadAxis enum to a string.
999 *
1000 * The caller should not SDL_free() the returned string.
1001 *
1002 * \param axis an enum value for a given SDL_GamepadAxis
1003 * \returns a string for the given axis, or NULL if an invalid axis is
1004 * specified. The string returned is of the format used by
1005 * SDL_Gamepad mapping strings.
1006 *
1007 * \since This function is available since SDL 3.0.0.
1008 *
1009 * \sa SDL_GetGamepadAxisFromString
1010 */
1011extern DECLSPEC const char * SDLCALL SDL_GetGamepadStringForAxis(SDL_GamepadAxis axis);
1012
1013/**
1014 * Query whether a gamepad has a given axis.
1015 *
1016 * This merely reports whether the gamepad's mapping defined this axis, as
1017 * that is all the information SDL has about the physical device.
1018 *
1019 * \param gamepad a gamepad
1020 * \param axis an axis enum value (an SDL_GamepadAxis value)
1021 * \returns SDL_TRUE if the gamepad has this axis, SDL_FALSE otherwise.
1022 *
1023 * \since This function is available since SDL 3.0.0.
1024 *
1025 * \sa SDL_GamepadHasButton
1026 * \sa SDL_GetGamepadAxis
1027 */
1028extern DECLSPEC SDL_bool SDLCALL SDL_GamepadHasAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
1029
1030/**
1031 * Get the current state of an axis control on a gamepad.
1032 *
1033 * The axis indices start at index 0.
1034 *
1035 * For thumbsticks, the state is a value ranging from -32768 (up/left) to
1036 * 32767 (down/right).
1037 *
1038 * Triggers range from 0 when released to 32767 when fully pressed, and never
1039 * return a negative value. Note that this differs from the value reported by
1040 * the lower-level SDL_GetJoystickAxis(), which normally uses the full range.
1041 *
1042 * \param gamepad a gamepad
1043 * \param axis an axis index (one of the SDL_GamepadAxis values)
1044 * \returns axis state (including 0) on success or 0 (also) on failure; call
1045 * SDL_GetError() for more information.
1046 *
1047 * \since This function is available since SDL 3.0.0.
1048 *
1049 * \sa SDL_GamepadHasAxis
1050 * \sa SDL_GetGamepadButton
1051 */
1052extern DECLSPEC Sint16 SDLCALL SDL_GetGamepadAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
1053
1054/**
1055 * Convert a string into an SDL_GamepadButton enum.
1056 *
1057 * This function is called internally to translate SDL_Gamepad mapping strings
1058 * for the underlying joystick device into the consistent SDL_Gamepad mapping.
1059 * You do not normally need to call this function unless you are parsing
1060 * SDL_Gamepad mappings in your own code.
1061 *
1062 * \param str string representing a SDL_Gamepad axis
1063 * \returns the SDL_GamepadButton enum corresponding to the input string, or
1064 * `SDL_GAMEPAD_BUTTON_INVALID` if no match was found.
1065 *
1066 * \since This function is available since SDL 3.0.0.
1067 *
1068 * \sa SDL_GetGamepadStringForButton
1069 */
1070extern DECLSPEC SDL_GamepadButton SDLCALL SDL_GetGamepadButtonFromString(const char *str);
1071
1072/**
1073 * Convert from an SDL_GamepadButton enum to a string.
1074 *
1075 * The caller should not SDL_free() the returned string.
1076 *
1077 * \param button an enum value for a given SDL_GamepadButton
1078 * \returns a string for the given button, or NULL if an invalid button is
1079 * specified. The string returned is of the format used by
1080 * SDL_Gamepad mapping strings.
1081 *
1082 * \since This function is available since SDL 3.0.0.
1083 *
1084 * \sa SDL_GetGamepadButtonFromString
1085 */
1086extern DECLSPEC const char* SDLCALL SDL_GetGamepadStringForButton(SDL_GamepadButton button);
1087
1088/**
1089 * Query whether a gamepad has a given button.
1090 *
1091 * This merely reports whether the gamepad's mapping defined this button, as
1092 * that is all the information SDL has about the physical device.
1093 *
1094 * \param gamepad a gamepad
1095 * \param button a button enum value (an SDL_GamepadButton value)
1096 * \returns SDL_TRUE if the gamepad has this button, SDL_FALSE otherwise.
1097 *
1098 * \since This function is available since SDL 3.0.0.
1099 *
1100 * \sa SDL_GamepadHasAxis
1101 */
1102extern DECLSPEC SDL_bool SDLCALL SDL_GamepadHasButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
1103
1104/**
1105 * Get the current state of a button on a gamepad.
1106 *
1107 * \param gamepad a gamepad
1108 * \param button a button index (one of the SDL_GamepadButton values)
1109 * \returns 1 for pressed state or 0 for not pressed state or error; call
1110 * SDL_GetError() for more information.
1111 *
1112 * \since This function is available since SDL 3.0.0.
1113 *
1114 * \sa SDL_GamepadHasButton
1115 * \sa SDL_GetGamepadAxis
1116 */
1117extern DECLSPEC Uint8 SDLCALL SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
1118
1119/**
1120 * Get the label of a button on a gamepad.
1121 *
1122 * \param type the type of gamepad to check
1123 * \param button a button index (one of the SDL_GamepadButton values)
1124 * \returns the SDL_GamepadButtonLabel enum corresponding to the button label
1125 *
1126 * \since This function is available since SDL 3.0.0.
1127 *
1128 * \sa SDL_GetGamepadButtonLabel
1129 */
1131
1132/**
1133 * Get the label of a button on a gamepad.
1134 *
1135 * \param gamepad a gamepad
1136 * \param button a button index (one of the SDL_GamepadButton values)
1137 * \returns the SDL_GamepadButtonLabel enum corresponding to the button label
1138 *
1139 * \since This function is available since SDL 3.0.0.
1140 *
1141 * \sa SDL_GetGamepadButtonLabelForType
1142 */
1144
1145/**
1146 * Get the number of touchpads on a gamepad.
1147 *
1148 * \param gamepad a gamepad
1149 * \returns number of touchpads
1150 *
1151 * \since This function is available since SDL 3.0.0.
1152 *
1153 * \sa SDL_GetNumGamepadTouchpadFingers
1154 */
1155extern DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpads(SDL_Gamepad *gamepad);
1156
1157/**
1158 * Get the number of supported simultaneous fingers on a touchpad on a game
1159 * gamepad.
1160 *
1161 * \param gamepad a gamepad
1162 * \param touchpad a touchpad
1163 * \returns number of supported simultaneous fingers
1164 *
1165 * \since This function is available since SDL 3.0.0.
1166 *
1167 * \sa SDL_GetGamepadTouchpadFinger
1168 * \sa SDL_GetNumGamepadTouchpads
1169 */
1170extern DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpadFingers(SDL_Gamepad *gamepad, int touchpad);
1171
1172/**
1173 * Get the current state of a finger on a touchpad on a gamepad.
1174 *
1175 * \param gamepad a gamepad
1176 * \param touchpad a touchpad
1177 * \param finger a finger
1178 * \param state filled with state
1179 * \param x filled with x position
1180 * \param y filled with y position
1181 * \param pressure filled with pressure value
1182 * \returns 0 on success or a negative error code on failure; call
1183 * SDL_GetError() for more information.
1184 *
1185 * \since This function is available since SDL 3.0.0.
1186 *
1187 * \sa SDL_GetNumGamepadTouchpadFingers
1188 */
1189extern DECLSPEC int SDLCALL SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure);
1190
1191/**
1192 * Return whether a gamepad has a particular sensor.
1193 *
1194 * \param gamepad The gamepad to query
1195 * \param type The type of sensor to query
1196 * \returns SDL_TRUE if the sensor exists, SDL_FALSE otherwise.
1197 *
1198 * \since This function is available since SDL 3.0.0.
1199 *
1200 * \sa SDL_GetGamepadSensorData
1201 * \sa SDL_GetGamepadSensorDataRate
1202 * \sa SDL_SetGamepadSensorEnabled
1203 */
1204extern DECLSPEC SDL_bool SDLCALL SDL_GamepadHasSensor(SDL_Gamepad *gamepad, SDL_SensorType type);
1205
1206/**
1207 * Set whether data reporting for a gamepad sensor is enabled.
1208 *
1209 * \param gamepad The gamepad to update
1210 * \param type The type of sensor to enable/disable
1211 * \param enabled Whether data reporting should be enabled
1212 * \returns 0 on success or a negative error code on failure; call
1213 * SDL_GetError() for more information.
1214 *
1215 * \since This function is available since SDL 3.0.0.
1216 *
1217 * \sa SDL_GamepadHasSensor
1218 * \sa SDL_GamepadSensorEnabled
1219 */
1220extern DECLSPEC int SDLCALL SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, SDL_bool enabled);
1221
1222/**
1223 * Query whether sensor data reporting is enabled for a gamepad.
1224 *
1225 * \param gamepad The gamepad to query
1226 * \param type The type of sensor to query
1227 * \returns SDL_TRUE if the sensor is enabled, SDL_FALSE otherwise.
1228 *
1229 * \since This function is available since SDL 3.0.0.
1230 *
1231 * \sa SDL_SetGamepadSensorEnabled
1232 */
1233extern DECLSPEC SDL_bool SDLCALL SDL_GamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type);
1234
1235/**
1236 * Get the data rate (number of events per second) of a gamepad sensor.
1237 *
1238 * \param gamepad The gamepad to query
1239 * \param type The type of sensor to query
1240 * \returns the data rate, or 0.0f if the data rate is not available.
1241 *
1242 * \since This function is available since SDL 3.0.0.
1243 */
1244extern DECLSPEC float SDLCALL SDL_GetGamepadSensorDataRate(SDL_Gamepad *gamepad, SDL_SensorType type);
1245
1246/**
1247 * Get the current state of a gamepad sensor.
1248 *
1249 * The number of values and interpretation of the data is sensor dependent.
1250 * See SDL_sensor.h for the details for each type of sensor.
1251 *
1252 * \param gamepad The gamepad to query
1253 * \param type The type of sensor to query
1254 * \param data A pointer filled with the current sensor state
1255 * \param num_values The number of values to write to data
1256 * \returns 0 on success or a negative error code on failure; call
1257 * SDL_GetError() for more information.
1258 *
1259 * \since This function is available since SDL 3.0.0.
1260 */
1261extern DECLSPEC int SDLCALL SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, SDL_SensorType type, float *data, int num_values);
1262
1263/**
1264 * Start a rumble effect on a gamepad.
1265 *
1266 * Each call to this function cancels any previous rumble effect, and calling
1267 * it with 0 intensity stops any rumbling.
1268 *
1269 * This function requires you to process SDL events or call
1270 * SDL_UpdateJoysticks() to update rumble state.
1271 *
1272 * \param gamepad The gamepad to vibrate
1273 * \param low_frequency_rumble The intensity of the low frequency (left)
1274 * rumble motor, from 0 to 0xFFFF
1275 * \param high_frequency_rumble The intensity of the high frequency (right)
1276 * rumble motor, from 0 to 0xFFFF
1277 * \param duration_ms The duration of the rumble effect, in milliseconds
1278 * \returns 0, or -1 if rumble isn't supported on this gamepad
1279 *
1280 * \since This function is available since SDL 3.0.0.
1281 */
1282extern DECLSPEC int SDLCALL SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
1283
1284/**
1285 * Start a rumble effect in the gamepad's triggers.
1286 *
1287 * Each call to this function cancels any previous trigger rumble effect, and
1288 * calling it with 0 intensity stops any rumbling.
1289 *
1290 * Note that this is rumbling of the _triggers_ and not the gamepad as a
1291 * whole. This is currently only supported on Xbox One gamepads. If you want
1292 * the (more common) whole-gamepad rumble, use SDL_RumbleGamepad() instead.
1293 *
1294 * This function requires you to process SDL events or call
1295 * SDL_UpdateJoysticks() to update rumble state.
1296 *
1297 * \param gamepad The gamepad to vibrate
1298 * \param left_rumble The intensity of the left trigger rumble motor, from 0
1299 * to 0xFFFF
1300 * \param right_rumble The intensity of the right trigger rumble motor, from 0
1301 * to 0xFFFF
1302 * \param duration_ms The duration of the rumble effect, in milliseconds
1303 * \returns 0 on success or a negative error code on failure; call
1304 * SDL_GetError() for more information.
1305 *
1306 * \since This function is available since SDL 3.0.0.
1307 *
1308 * \sa SDL_RumbleGamepad
1309 */
1310extern DECLSPEC int SDLCALL SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
1311
1312/**
1313 * Update a gamepad's LED color.
1314 *
1315 * An example of a joystick LED is the light on the back of a PlayStation 4's
1316 * DualShock 4 controller.
1317 *
1318 * For gamepads with a single color LED, the maximum of the RGB values will be
1319 * used as the LED brightness.
1320 *
1321 * \param gamepad The gamepad to update
1322 * \param red The intensity of the red LED
1323 * \param green The intensity of the green LED
1324 * \param blue The intensity of the blue LED
1325 * \returns 0 on success or a negative error code on failure; call
1326 * SDL_GetError() for more information.
1327 *
1328 * \since This function is available since SDL 3.0.0.
1329 */
1330extern DECLSPEC int SDLCALL SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue);
1331
1332/**
1333 * Send a gamepad specific effect packet
1334 *
1335 * \param gamepad The gamepad to affect
1336 * \param data The data to send to the gamepad
1337 * \param size The size of the data to send to the gamepad
1338 * \returns 0 on success or a negative error code on failure; call
1339 * SDL_GetError() for more information.
1340 *
1341 * \since This function is available since SDL 3.0.0.
1342 */
1343extern DECLSPEC int SDLCALL SDL_SendGamepadEffect(SDL_Gamepad *gamepad, const void *data, int size);
1344
1345/**
1346 * Close a gamepad previously opened with SDL_OpenGamepad().
1347 *
1348 * \param gamepad a gamepad identifier previously returned by
1349 * SDL_OpenGamepad()
1350 *
1351 * \since This function is available since SDL 3.0.0.
1352 *
1353 * \sa SDL_OpenGamepad
1354 */
1355extern DECLSPEC void SDLCALL SDL_CloseGamepad(SDL_Gamepad *gamepad);
1356
1357/**
1358 * Return the sfSymbolsName for a given button on a gamepad on Apple
1359 * platforms.
1360 *
1361 * \param gamepad the gamepad to query
1362 * \param button a button on the gamepad
1363 * \returns the sfSymbolsName or NULL if the name can't be found
1364 *
1365 * \since This function is available since SDL 3.0.0.
1366 *
1367 * \sa SDL_GetGamepadAppleSFSymbolsNameForAxis
1368 */
1369extern DECLSPEC const char* SDLCALL SDL_GetGamepadAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
1370
1371/**
1372 * Return the sfSymbolsName for a given axis on a gamepad on Apple platforms.
1373 *
1374 * \param gamepad the gamepad to query
1375 * \param axis an axis on the gamepad
1376 * \returns the sfSymbolsName or NULL if the name can't be found
1377 *
1378 * \since This function is available since SDL 3.0.0.
1379 *
1380 * \sa SDL_GetGamepadAppleSFSymbolsNameForButton
1381 */
1382extern DECLSPEC const char* SDLCALL SDL_GetGamepadAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
1383
1384
1385/* Ends C function definitions when using C++ */
1386#ifdef __cplusplus
1387}
1388#endif
1389#include <SDL3/SDL_close_code.h>
1390
1391#endif /* SDL_gamepad_h_ */
SDL_Gamepad * SDL_OpenGamepad(SDL_JoystickID instance_id)
SDL_bool SDL_GamepadHasAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis)
const char * SDL_GetGamepadInstancePath(SDL_JoystickID instance_id)
int SDL_AddGamepadMappingsFromIO(SDL_IOStream *src, SDL_bool closeio)
int SDL_GetNumGamepadTouchpads(SDL_Gamepad *gamepad)
SDL_GamepadAxis
@ SDL_GAMEPAD_AXIS_RIGHTX
@ SDL_GAMEPAD_AXIS_MAX
@ SDL_GAMEPAD_AXIS_RIGHT_TRIGGER
@ SDL_GAMEPAD_AXIS_LEFTX
@ SDL_GAMEPAD_AXIS_INVALID
@ SDL_GAMEPAD_AXIS_LEFTY
@ SDL_GAMEPAD_AXIS_LEFT_TRIGGER
@ SDL_GAMEPAD_AXIS_RIGHTY
int SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure)
Uint8 SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button)
SDL_GamepadType SDL_GetGamepadType(SDL_Gamepad *gamepad)
int SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, SDL_SensorType type, float *data, int num_values)
SDL_GamepadAxis SDL_GetGamepadAxisFromString(const char *str)
SDL_JoystickID SDL_GetGamepadInstanceID(SDL_Gamepad *gamepad)
SDL_GamepadButton SDL_GetGamepadButtonFromString(const char *str)
struct SDL_Gamepad SDL_Gamepad
Definition SDL_gamepad.h:60
SDL_JoystickPowerLevel SDL_GetGamepadPowerLevel(SDL_Gamepad *gamepad)
SDL_bool SDL_GamepadHasButton(SDL_Gamepad *gamepad, SDL_GamepadButton button)
SDL_GamepadBindingType
@ SDL_GAMEPAD_BINDTYPE_HAT
@ SDL_GAMEPAD_BINDTYPE_BUTTON
@ SDL_GAMEPAD_BINDTYPE_NONE
@ SDL_GAMEPAD_BINDTYPE_AXIS
char ** SDL_GetGamepadMappings(int *count)
Uint16 SDL_GetGamepadFirmwareVersion(SDL_Gamepad *gamepad)
SDL_bool SDL_HasGamepad(void)
SDL_GamepadButton
Definition SDL_gamepad.h:99
@ SDL_GAMEPAD_BUTTON_LEFT_PADDLE2
@ SDL_GAMEPAD_BUTTON_WEST
@ SDL_GAMEPAD_BUTTON_EAST
@ SDL_GAMEPAD_BUTTON_MISC2
@ SDL_GAMEPAD_BUTTON_GUIDE
@ SDL_GAMEPAD_BUTTON_LEFT_STICK
@ SDL_GAMEPAD_BUTTON_TOUCHPAD
@ SDL_GAMEPAD_BUTTON_MISC4
@ SDL_GAMEPAD_BUTTON_MISC5
@ SDL_GAMEPAD_BUTTON_LEFT_SHOULDER
@ SDL_GAMEPAD_BUTTON_DPAD_DOWN
@ SDL_GAMEPAD_BUTTON_MAX
@ SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1
@ SDL_GAMEPAD_BUTTON_INVALID
@ SDL_GAMEPAD_BUTTON_MISC6
@ SDL_GAMEPAD_BUTTON_MISC1
@ SDL_GAMEPAD_BUTTON_BACK
@ SDL_GAMEPAD_BUTTON_DPAD_UP
@ SDL_GAMEPAD_BUTTON_LEFT_PADDLE1
@ SDL_GAMEPAD_BUTTON_RIGHT_STICK
@ SDL_GAMEPAD_BUTTON_START
@ SDL_GAMEPAD_BUTTON_DPAD_RIGHT
@ SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER
@ SDL_GAMEPAD_BUTTON_MISC3
@ SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2
@ SDL_GAMEPAD_BUTTON_SOUTH
@ SDL_GAMEPAD_BUTTON_DPAD_LEFT
@ SDL_GAMEPAD_BUTTON_NORTH
int SDL_SetGamepadMapping(SDL_JoystickID instance_id, const char *mapping)
SDL_Gamepad * SDL_GetGamepadFromInstanceID(SDL_JoystickID instance_id)
char * SDL_GetGamepadMapping(SDL_Gamepad *gamepad)
Uint16 SDL_GetGamepadProductVersion(SDL_Gamepad *gamepad)
SDL_GamepadType SDL_GetGamepadTypeFromString(const char *str)
char * SDL_GetGamepadInstanceMapping(SDL_JoystickID instance_id)
Uint16 SDL_GetGamepadProduct(SDL_Gamepad *gamepad)
int SDL_SendGamepadEffect(SDL_Gamepad *gamepad, const void *data, int size)
char * SDL_GetGamepadMappingForGUID(SDL_JoystickGUID guid)
int SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, SDL_bool enabled)
int SDL_GetGamepadPlayerIndex(SDL_Gamepad *gamepad)
const char * SDL_GetGamepadName(SDL_Gamepad *gamepad)
const char * SDL_GetGamepadAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis)
int SDL_AddGamepadMapping(const char *mapping)
int SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms)
SDL_bool SDL_GamepadConnected(SDL_Gamepad *gamepad)
int SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
const char * SDL_GetGamepadSerial(SDL_Gamepad *gamepad)
const char * SDL_GetGamepadStringForAxis(SDL_GamepadAxis axis)
int SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue)
SDL_GamepadButtonLabel SDL_GetGamepadButtonLabelForType(SDL_GamepadType type, SDL_GamepadButton button)
SDL_PropertiesID SDL_GetGamepadProperties(SDL_Gamepad *gamepad)
const char * SDL_GetGamepadAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button)
const char * SDL_GetGamepadStringForType(SDL_GamepadType type)
const char * SDL_GetGamepadStringForButton(SDL_GamepadButton button)
Uint16 SDL_GetGamepadInstanceProduct(SDL_JoystickID instance_id)
void SDL_SetGamepadEventsEnabled(SDL_bool enabled)
SDL_GamepadButtonLabel SDL_GetGamepadButtonLabel(SDL_Gamepad *gamepad, SDL_GamepadButton button)
SDL_Joystick * SDL_GetGamepadJoystick(SDL_Gamepad *gamepad)
Uint16 SDL_GetGamepadInstanceProductVersion(SDL_JoystickID instance_id)
SDL_bool SDL_IsGamepad(SDL_JoystickID instance_id)
int SDL_SetGamepadPlayerIndex(SDL_Gamepad *gamepad, int player_index)
int SDL_AddGamepadMappingsFromFile(const char *file)
SDL_Gamepad * SDL_GetGamepadFromPlayerIndex(int player_index)
SDL_GamepadType SDL_GetRealGamepadInstanceType(SDL_JoystickID instance_id)
SDL_bool SDL_GamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type)
const char * SDL_GetGamepadInstanceName(SDL_JoystickID instance_id)
Uint64 SDL_GetGamepadSteamHandle(SDL_Gamepad *gamepad)
Sint16 SDL_GetGamepadAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis)
void SDL_UpdateGamepads(void)
void SDL_CloseGamepad(SDL_Gamepad *gamepad)
SDL_GamepadType
Definition SDL_gamepad.h:63
@ SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT
Definition SDL_gamepad.h:72
@ SDL_GAMEPAD_TYPE_PS5
Definition SDL_gamepad.h:70
@ SDL_GAMEPAD_TYPE_UNKNOWN
Definition SDL_gamepad.h:64
@ SDL_GAMEPAD_TYPE_MAX
Definition SDL_gamepad.h:75
@ SDL_GAMEPAD_TYPE_XBOX360
Definition SDL_gamepad.h:66
@ SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT
Definition SDL_gamepad.h:73
@ SDL_GAMEPAD_TYPE_XBOXONE
Definition SDL_gamepad.h:67
@ SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO
Definition SDL_gamepad.h:71
@ SDL_GAMEPAD_TYPE_PS4
Definition SDL_gamepad.h:69
@ SDL_GAMEPAD_TYPE_PS3
Definition SDL_gamepad.h:68
@ SDL_GAMEPAD_TYPE_STANDARD
Definition SDL_gamepad.h:65
@ SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_PAIR
Definition SDL_gamepad.h:74
SDL_JoystickGUID SDL_GetGamepadInstanceGUID(SDL_JoystickID instance_id)
Uint16 SDL_GetGamepadInstanceVendor(SDL_JoystickID instance_id)
SDL_bool SDL_GamepadHasSensor(SDL_Gamepad *gamepad, SDL_SensorType type)
int SDL_GetGamepadInstancePlayerIndex(SDL_JoystickID instance_id)
SDL_GamepadType SDL_GetGamepadInstanceType(SDL_JoystickID instance_id)
SDL_GamepadButtonLabel
@ SDL_GAMEPAD_BUTTON_LABEL_CIRCLE
@ SDL_GAMEPAD_BUTTON_LABEL_X
@ SDL_GAMEPAD_BUTTON_LABEL_TRIANGLE
@ SDL_GAMEPAD_BUTTON_LABEL_B
@ SDL_GAMEPAD_BUTTON_LABEL_SQUARE
@ SDL_GAMEPAD_BUTTON_LABEL_CROSS
@ SDL_GAMEPAD_BUTTON_LABEL_UNKNOWN
@ SDL_GAMEPAD_BUTTON_LABEL_Y
@ SDL_GAMEPAD_BUTTON_LABEL_A
SDL_bool SDL_GamepadEventsEnabled(void)
SDL_GamepadBinding ** SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count)
Uint16 SDL_GetGamepadVendor(SDL_Gamepad *gamepad)
int SDL_GetNumGamepadTouchpadFingers(SDL_Gamepad *gamepad, int touchpad)
const char * SDL_GetGamepadPath(SDL_Gamepad *gamepad)
float SDL_GetGamepadSensorDataRate(SDL_Gamepad *gamepad, SDL_SensorType type)
SDL_GamepadType SDL_GetRealGamepadType(SDL_Gamepad *gamepad)
int SDL_ReloadGamepadMappings(void)
SDL_JoystickID * SDL_GetGamepads(int *count)
struct SDL_IOStream SDL_IOStream
Uint32 SDL_JoystickID
SDL_JoystickPowerLevel
struct SDL_Joystick SDL_Joystick
Uint32 SDL_PropertiesID
SDL_SensorType
Definition SDL_sensor.h:70
uint8_t Uint8
Definition SDL_stdinc.h:150
uint16_t Uint16
Definition SDL_stdinc.h:162
SDL_MALLOC size_t size
Definition SDL_stdinc.h:410
int SDL_bool
Definition SDL_stdinc.h:137
int16_t Sint16
Definition SDL_stdinc.h:156
uint64_t Uint64
Definition SDL_stdinc.h:187
uint32_t Uint32
Definition SDL_stdinc.h:174
SDL_GamepadButton button
SDL_GamepadBindingType input_type
union SDL_GamepadBinding::@0 input
SDL_GamepadBindingType output_type
union SDL_GamepadBinding::@1 output
SDL_GamepadAxis axis