GamepadsSDL 3.2

SDL_GetGamepadButton

Asks whether a gamepad button is held right now.

Signature

bool SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);

How it works

The polling counterpart of the SDL_EVENT_GAMEPAD_BUTTON_DOWN / _UP events. Face buttons are named by POSITION, because the labels differ between brands: SOUTH is the bottom one (Xbox A, PlayStation Cross), EAST the right one (Xbox B, PlayStation Circle).

Parameters

gamepadSDL_Gamepad *

The gamepad.

buttonSDL_GamepadButton

Which button.

Common values

SDL_GAMEPAD_BUTTON_SOUTH / EAST / WEST / NORTH
The four face buttons, by position.
SDL_GAMEPAD_BUTTON_DPAD_UP / DOWN / LEFT / RIGHT
The D-pad.
SDL_GAMEPAD_BUTTON_LEFT_SHOULDER / RIGHT_SHOULDER
Bumpers (LB/RB, L1/R1).
SDL_GAMEPAD_BUTTON_START / BACK / GUIDE
Menu buttons.
SDL_GAMEPAD_BUTTON_LEFT_STICK / RIGHT_STICK
Pressing a stick in.

Return value

true while the button is held.

Example

example.cpp
1if (SDL_GetGamepadButton(pad, SDL_GAMEPAD_BUTTON_SOUTH) && player.onGround)
2    player.jump();
Official SDL wiki