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