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