Module gamepad
dep_sdl3
only.Expand description
SDL provides a low-level joystick API, which just treats joysticks as an arbitrary pile of buttons, axes, and hat switches. If you’re planning to write your own control configuration screen, this can give you a lot of flexibility, but that’s a lot of work, and most things that we consider “joysticks” now are actually console-style gamepads. So SDL provides the gamepad API on top of the lower-level joystick functionality.
The difference between a joystick and a gamepad is that a gamepad tells you where a button or axis is on the device. You don’t speak to gamepads in terms of arbitrary numbers like “button 3” or “axis 2” but in standard locations: the d-pad, the shoulder buttons, triggers, A/B/X/Y (or X/O/Square/Triangle, if you will).
One turns a joystick into a gamepad by providing a magic configuration string, which tells SDL the details of a specific device: when you see this specific hardware, if button 2 gets pressed, this is actually D-Pad Up, etc.
SDL has many popular controllers configured out of the box, and users can add their own controller details through an environment variable if it’s otherwise unknown to SDL.
In order to use these functions, [SDL_Init()
] must have been called with the
[SDL_INIT_GAMEPAD
] flag. This causes SDL to scan the system for gamepads, and
load appropriate drivers.
If you would like to receive gamepad updates while the application is in
the background, you should set the following hint before calling
[SDL_Init()
]: [SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
]
Gamepads support various optional features such as rumble, color LEDs,
touchpad, gyro, etc. The support for these features varies depending on the
controller and OS support available. You can check for LED and rumble
capabilities at runtime by calling SDL_GetGamepadProperties()
and checking
the various capability properties. You can check for touchpad by calling
SDL_GetNumGamepadTouchpads()
and check for gyro and accelerometer by
calling SDL_GamepadHasSensor()
.
By default SDL will try to use the most capable driver available, but you can tune which OS drivers to use with the various joystick hints in SDL_hints.h.
Your application should always support gamepad hotplugging. On some platforms like Xbox, Steam Deck, etc., this is a requirement for certification. On other platforms, like macOS and Windows when using Windows.Gaming.Input, controllers may not be available at startup and will come in at some point after you’ve started processing events.
Structs§
- SDL_
Gamepad - The structure used to identify an SDL gamepad
- SDL_
Gamepad Axis - The list of axes available on a gamepad
- SDL_
Gamepad Binding - A mapping between one joystick input to a gamepad control.
- SDL_
Gamepad Binding Type - Types of gamepad control bindings.
- SDL_
Gamepad Binding__ Anon Union1__ Anon Struct1 - SDL_
Gamepad Binding__ Anon Union1__ Anon Struct2 - SDL_
Gamepad Binding__ Anon Union2__ Anon Struct1 - SDL_
Gamepad Button - The list of buttons available on a gamepad
- SDL_
Gamepad Button Label - The set of gamepad button labels
- SDL_
Gamepad Type - Standard gamepad types.
Constants§
- SDL_
GAMEPAD_ AXIS_ COUNT - SDL_
GAMEPAD_ AXIS_ INVALID - SDL_
GAMEPAD_ AXIS_ LEFTX - SDL_
GAMEPAD_ AXIS_ LEFTY - SDL_
GAMEPAD_ AXIS_ LEFT_ TRIGGER - SDL_
GAMEPAD_ AXIS_ RIGHTX - SDL_
GAMEPAD_ AXIS_ RIGHTY - SDL_
GAMEPAD_ AXIS_ RIGHT_ TRIGGER - SDL_
GAMEPAD_ BINDTYPE_ AXIS - SDL_
GAMEPAD_ BINDTYPE_ BUTTON - SDL_
GAMEPAD_ BINDTYPE_ HAT - SDL_
GAMEPAD_ BINDTYPE_ NONE - SDL_
GAMEPAD_ BUTTON_ BACK - SDL_
GAMEPAD_ BUTTON_ COUNT - SDL_
GAMEPAD_ BUTTON_ DPAD_ DOWN - SDL_
GAMEPAD_ BUTTON_ DPAD_ LEFT - SDL_
GAMEPAD_ BUTTON_ DPAD_ RIGHT - SDL_
GAMEPAD_ BUTTON_ DPAD_ UP - SDL_
GAMEPAD_ BUTTON_ EAST - Right face button (e.g. Xbox B button)
- SDL_
GAMEPAD_ BUTTON_ GUIDE - SDL_
GAMEPAD_ BUTTON_ INVALID - SDL_
GAMEPAD_ BUTTON_ LABEL_ A - SDL_
GAMEPAD_ BUTTON_ LABEL_ B - SDL_
GAMEPAD_ BUTTON_ LABEL_ CIRCLE - SDL_
GAMEPAD_ BUTTON_ LABEL_ CROSS - SDL_
GAMEPAD_ BUTTON_ LABEL_ SQUARE - SDL_
GAMEPAD_ BUTTON_ LABEL_ TRIANGLE - SDL_
GAMEPAD_ BUTTON_ LABEL_ UNKNOWN - SDL_
GAMEPAD_ BUTTON_ LABEL_ X - SDL_
GAMEPAD_ BUTTON_ LABEL_ Y - SDL_
GAMEPAD_ BUTTON_ LEFT_ PADDL E1 - Upper or primary paddle, under your left hand (e.g. Xbox Elite paddle P3)
- SDL_
GAMEPAD_ BUTTON_ LEFT_ PADDL E2 - Lower or secondary paddle, under your left hand (e.g. Xbox Elite paddle P4)
- SDL_
GAMEPAD_ BUTTON_ LEFT_ SHOULDER - SDL_
GAMEPAD_ BUTTON_ LEFT_ STICK - 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)
- SDL_
GAMEPAD_ BUTTON_ MISC2 - Additional button
- SDL_
GAMEPAD_ BUTTON_ MISC3 - Additional button
- SDL_
GAMEPAD_ BUTTON_ MISC4 - Additional button
- SDL_
GAMEPAD_ BUTTON_ MISC5 - Additional button
- SDL_
GAMEPAD_ BUTTON_ MISC6 - Additional button
- SDL_
GAMEPAD_ BUTTON_ NORTH - Top face button (e.g. Xbox Y button)
- SDL_
GAMEPAD_ BUTTON_ RIGHT_ PADDL E1 - Upper or primary paddle, under your right hand (e.g. Xbox Elite paddle P1)
- SDL_
GAMEPAD_ BUTTON_ RIGHT_ PADDL E2 - Lower or secondary paddle, under your right hand (e.g. Xbox Elite paddle P2)
- SDL_
GAMEPAD_ BUTTON_ RIGHT_ SHOULDER - SDL_
GAMEPAD_ BUTTON_ RIGHT_ STICK - SDL_
GAMEPAD_ BUTTON_ SOUTH - Bottom face button (e.g. Xbox A button)
- SDL_
GAMEPAD_ BUTTON_ START - SDL_
GAMEPAD_ BUTTON_ TOUCHPAD - PS4/PS5 touchpad button
- SDL_
GAMEPAD_ BUTTON_ WEST - Left face button (e.g. Xbox X button)
- SDL_
GAMEPAD_ TYPE_ COUNT - SDL_
GAMEPAD_ TYPE_ NINTENDO_ SWITCH_ JOYCON_ LEFT - SDL_
GAMEPAD_ TYPE_ NINTENDO_ SWITCH_ JOYCON_ PAIR - SDL_
GAMEPAD_ TYPE_ NINTENDO_ SWITCH_ JOYCON_ RIGHT - SDL_
GAMEPAD_ TYPE_ NINTENDO_ SWITCH_ PRO - SDL_
GAMEPAD_ TYPE_ PS3 - SDL_
GAMEPAD_ TYPE_ PS4 - SDL_
GAMEPAD_ TYPE_ PS5 - SDL_
GAMEPAD_ TYPE_ STANDARD - SDL_
GAMEPAD_ TYPE_ UNKNOWN - SDL_
GAMEPAD_ TYPE_ XBOX360 - SDL_
GAMEPAD_ TYPE_ XBOXONE - SDL_
PROP_ GAMEPAD_ CAP_ MONO_ LED_ BOOLEAN - SDL_
PROP_ GAMEPAD_ CAP_ PLAYER_ LED_ BOOLEAN - SDL_
PROP_ GAMEPAD_ CAP_ RGB_ LED_ BOOLEAN - SDL_
PROP_ GAMEPAD_ CAP_ RUMBLE_ BOOLEAN - SDL_
PROP_ GAMEPAD_ CAP_ TRIGGER_ RUMBLE_ BOOLEAN
Functions§
- SDL_
AddGamepad ⚠Mapping - Add support for gamepads that SDL is unaware of or change the binding of an existing gamepad.
- SDL_
AddGamepad ⚠Mappings From File - Load a set of gamepad mappings from a file.
- SDL_
AddGamepad ⚠Mappings FromIO - Load a set of gamepad mappings from an
SDL_IOStream
. - SDL_
Close ⚠Gamepad - Close a gamepad previously opened with
SDL_OpenGamepad()
. - SDL_
Gamepad ⚠Connected - Check if a gamepad has been opened and is currently connected.
- SDL_
Gamepad ⚠Events Enabled - Query the state of gamepad event processing.
- SDL_
Gamepad ⚠HasAxis - Query whether a gamepad has a given axis.
- SDL_
Gamepad ⚠HasButton - Query whether a gamepad has a given button.
- SDL_
Gamepad ⚠HasSensor - Return whether a gamepad has a particular sensor.
- SDL_
Gamepad ⚠Sensor Enabled - Query whether sensor data reporting is enabled for a gamepad.
- SDL_
GetGamepad ⚠AppleSF Symbols Name ForAxis - Return the sfSymbolsName for a given axis on a gamepad on Apple platforms.
- SDL_
GetGamepad ⚠AppleSF Symbols Name ForButton - Return the sfSymbolsName for a given button on a gamepad on Apple platforms.
- SDL_
GetGamepad ⚠Axis - Get the current state of an axis control on a gamepad.
- SDL_
GetGamepad ⚠Axis From String - Convert a string into
SDL_GamepadAxis
enum. - SDL_
GetGamepad ⚠Bindings - Get the SDL joystick layer bindings for a gamepad.
- SDL_
GetGamepad ⚠Button - Get the current state of a button on a gamepad.
- SDL_
GetGamepad ⚠Button From String - Convert a string into an
SDL_GamepadButton
enum. - SDL_
GetGamepad ⚠Button Label - Get the label of a button on a gamepad.
- SDL_
GetGamepad ⚠Button Label ForType - Get the label of a button on a gamepad.
- SDL_
GetGamepad ⚠Connection State - Get the connection state of a gamepad.
- SDL_
GetGamepad ⚠Firmware Version - Get the firmware version of an opened gamepad, if available.
- SDL_
GetGamepad ⚠FromID - Get the
SDL_Gamepad
associated with a joystick instance ID, if it has been opened. - SDL_
GetGamepad ⚠From Player Index - Get the
SDL_Gamepad
associated with a player index. - SDL_
GetGamepadGUID ⚠ForID - Get the implementation-dependent GUID of a gamepad.
- SDL_
GetGamepadID ⚠ - Get the instance ID of an opened gamepad.
- SDL_
GetGamepad ⚠Joystick - Get the underlying joystick from a gamepad.
- SDL_
GetGamepad ⚠Mapping - Get the current mapping of a gamepad.
- SDL_
GetGamepad ⚠Mapping ForGUID - Get the gamepad mapping string for a given GUID.
- SDL_
GetGamepad ⚠Mapping ForID - Get the mapping of a gamepad.
- SDL_
GetGamepad ⚠Mappings - Get the current gamepad mappings.
- SDL_
GetGamepad ⚠Name - Get the implementation-dependent name for an opened gamepad.
- SDL_
GetGamepad ⚠Name ForID - Get the implementation dependent name of a gamepad.
- SDL_
GetGamepad ⚠Path - Get the implementation-dependent path for an opened gamepad.
- SDL_
GetGamepad ⚠Path ForID - Get the implementation dependent path of a gamepad.
- SDL_
GetGamepad ⚠Player Index - Get the player index of an opened gamepad.
- SDL_
GetGamepad ⚠Player Index ForID - Get the player index of a gamepad.
- SDL_
GetGamepad ⚠Power Info - Get the battery state of a gamepad.
- SDL_
GetGamepad ⚠Product - Get the USB product ID of an opened gamepad, if available.
- SDL_
GetGamepad ⚠Product ForID - Get the USB product ID of a gamepad, if available.
- SDL_
GetGamepad ⚠Product Version - Get the product version of an opened gamepad, if available.
- SDL_
GetGamepad ⚠Product Version ForID - Get the product version of a gamepad, if available.
- SDL_
GetGamepad ⚠Properties - Get the properties associated with an opened gamepad.
- SDL_
GetGamepad ⚠Sensor Data - Get the current state of a gamepad sensor.
- SDL_
GetGamepad ⚠Sensor Data Rate - Get the data rate (number of events per second) of a gamepad sensor.
- SDL_
GetGamepad ⚠Serial - Get the serial number of an opened gamepad, if available.
- SDL_
GetGamepad ⚠Steam Handle - Get the Steam Input handle of an opened gamepad, if available.
- SDL_
GetGamepad ⚠String ForAxis - Convert from an
SDL_GamepadAxis
enum to a string. - SDL_
GetGamepad ⚠String ForButton - Convert from an
SDL_GamepadButton
enum to a string. - SDL_
GetGamepad ⚠String ForType - Convert from an
SDL_GamepadType
enum to a string. - SDL_
GetGamepad ⚠Touchpad Finger - Get the current state of a finger on a touchpad on a gamepad.
- SDL_
GetGamepad ⚠Type - Get the type of an opened gamepad.
- SDL_
GetGamepad ⚠Type ForID - Get the type of a gamepad.
- SDL_
GetGamepad ⚠Type From String - Convert a string into
SDL_GamepadType
enum. - SDL_
GetGamepad ⚠Vendor - Get the USB vendor ID of an opened gamepad, if available.
- SDL_
GetGamepad ⚠Vendor ForID - Get the USB vendor ID of a gamepad, if available.
- SDL_
GetGamepads ⚠ - Get a list of currently connected gamepads.
- SDL_
GetNum ⚠Gamepad Touchpad Fingers - Get the number of supported simultaneous fingers on a touchpad on a game gamepad.
- SDL_
GetNum ⚠Gamepad Touchpads - Get the number of touchpads on a gamepad.
- SDL_
GetReal ⚠Gamepad Type - Get the type of an opened gamepad, ignoring any mapping override.
- SDL_
GetReal ⚠Gamepad Type ForID - Get the type of a gamepad, ignoring any mapping override.
- SDL_
HasGamepad ⚠ - Return whether a gamepad is currently connected.
- SDL_
IsGamepad ⚠ - Check if the given joystick is supported by the gamepad interface.
- SDL_
Open ⚠Gamepad - Open a gamepad for use.
- SDL_
Reload ⚠Gamepad Mappings - Reinitialize the SDL mapping database to its initial state.
- SDL_
Rumble ⚠Gamepad - Start a rumble effect on a gamepad.
- SDL_
Rumble ⚠Gamepad Triggers - Start a rumble effect in the gamepad’s triggers.
- SDL_
Send ⚠Gamepad Effect - Send a gamepad specific effect packet.
- SDL_
SetGamepad ⚠Events Enabled - Set the state of gamepad event processing.
- SDL_
SetGamepadLED ⚠ - Update a gamepad’s LED color.
- SDL_
SetGamepad ⚠Mapping - Set the current mapping of a joystick or gamepad.
- SDL_
SetGamepad ⚠Player Index - Set the player index of an opened gamepad.
- SDL_
SetGamepad ⚠Sensor Enabled - Set whether data reporting for a gamepad sensor is enabled.
- SDL_
Update ⚠Gamepads - Manually pump gamepad updates if not using the loop.