Skip to content

gamepad

gamepad

Gamepads.

Controllers are opened automatically when they connect (the event loop calls openGamepad), and the gamepadpressed, gamepadreleased and gamepadaxis callbacks report input. You can also poll with isGamepadDown and gamepadAxis. Built on the SDL3 gamepad API, so anything SDL recognizes as a gamepad works.

toGamepadButton

proc toGamepadButton(b: SDL_GamepadButton): GamepadButton

The nim2d GamepadButton for an SDL gamepad button.

Parameters

  • b (SDL_GamepadButton)

Returns

GamepadButton

toGamepadAxis

proc toGamepadAxis(a: SDL_GamepadAxis): GamepadAxis

The nim2d GamepadAxis for an SDL gamepad axis.

Parameters

  • a (SDL_GamepadAxis)

Returns

GamepadAxis

openGamepad

proc openGamepad(id: GamepadId)

Open a controller. The event loop calls this when one connects, so games

normally never do.

Parameters

  • id (GamepadId)

closeGamepad

proc closeGamepad(id: GamepadId)

Close a controller. The event loop calls this when one disconnects.

Parameters

  • id (GamepadId)

connectedGamepads

proc connectedGamepads(): seq[GamepadId]

The ids of every connected controller.

Returns

seq[GamepadId]

isGamepadDown

proc isGamepadDown(id: GamepadId; button: GamepadButton): bool

Whether a controller button is currently held.

Parameters

  • id (GamepadId)
  • button (GamepadButton)

Returns

bool

gamepadAxis

proc gamepadAxis(id: GamepadId; axis: GamepadAxis): float

Axis value from -1 to 1 (triggers run 0 to 1).

Parameters

  • id (GamepadId)
  • axis (GamepadAxis)

Returns

float

Generated with mkdocstrings-nim