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