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