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