v2026.5.3
All Bundles
Bundle SDL2 multimedia library for 2D graphics, input handling, audio playback, and window management. Core types: Window, Renderer, Texture, Surface, Event, and Mixer. Compile with -lib sdl2.

GameController

Handles inputs from joysticks

Operations

AddMapping # function

Add support for controllers that SDL is unaware of or to cause an existing controller to have a different binding

function : AddMapping(mapping_string:String) ~ Int

Parameters

NameTypeDescription
mapping_stringStringthe mapping string

Return

TypeDescription
Int1 if a new mapping is added, 0 if an existing mapping is updated, -1 on error

Close #

Close a game controller previously opened

method : public : Close() ~ Nil

EventState # function

Query or change current state of Game Controller events

function : EventState(state:Int) ~ Int

Parameters

NameTypeDescription
stateIntcan be one of 'SDL_QUERY', 'SDL_IGNORE', or 'SDL_ENABLE'

Return

TypeDescription
Intthe same value passed to the function, with exception to -1, which will return the current state

FromInstanceID # function

Get the SDL_GameController associated with an instance id

function : FromInstanceID(joyid:Int) ~ GameController

Parameters

NameTypeDescription
joyidIntthe instance id to get the SDL_GameController for

Return

TypeDescription
GameControlleran SDL_GameController on success or NULL on failure

GetAttached #

Check if a controller has been opened and is currently connected.

method : public : GetAttached() ~ Bool

Return

TypeDescription
Booltrue if the controller has been opened and is currently connected, or false if not

GetAxis #

Get the current state of an axis control on a game controller

method : public : GetAxis(axis:GameControllerAxis) ~ Int

Parameters

NameTypeDescription
axisGameControllerAxisan axis index (one of the SDL_GameControllerAxis values)

Return

TypeDescription
Intaxis state (including 0) on success or 0 (also) on failure

GetAxisFromString # function

Convert a string into SDL_GameControllerAxis enum

function : GetAxisFromString(str:String) ~ GameControllerAxis

Parameters

NameTypeDescription
strStringstring representing a SDL_GameController axis

Return

TypeDescription
GameControllerAxisthe GameControllerAxis enum corresponding to the input string, or SDL_CONTROLLER_AXIS_INVALID if no match was found.

GetBindForAxis #

Get the SDL joystick layer binding for a controller axis mapping

method : public : GetBindForAxis(axis:GameControllerAxis) ~ GameControllerButtonBind

Parameters

NameTypeDescription
axisGameControllerAxisan axis enum value (one of the SDL_GameControllerAxis values)

Return

TypeDescription
GameControllerButtonBindSDL_GameControllerButtonBind describing the bind

GetBindForButton #

Get the SDL joystick layer binding for a controller button mapping

method : public : GetBindForButton(button:GameControllerButton) ~ GameControllerButtonBind

Parameters

NameTypeDescription
buttonGameControllerButtonan button enum value (an SDL_GameControllerButton value)

Return

TypeDescription
GameControllerButtonBindSDL_GameControllerButtonBind describing the bind

GetButton #

Get the current state of a button on a game controller

method : public : GetButton(button:GameControllerButton) ~ Int

Parameters

NameTypeDescription
buttonGameControllerButtona button index (one of the SDL_GameControllerButton values)

Return

TypeDescription
Int1 for pressed state or 0 for not pressed state or error

GetButtonFromString # function

Convert a string into an SDL_GameControllerButton enum

function : GetButtonFromString(str:String) ~ GameControllerButton

Parameters

NameTypeDescription
strStringstring representing a SDL_GameController axis

Return

TypeDescription
GameControllerButtonthe SDL_GameControllerButton enum corresponding to the input string

GetJoystick #

This function will give you a SDL_Joystick object, which allows you to use the SDL_Joystick functions with a SDL_GameController object

method : public : GetJoystick() ~ Joystick

Return

TypeDescription
Joysticka Joystick object

GetNumTouchpads #

Get the number of touchpads on a game controller.

method : public : GetNumTouchpads() ~ Int

GetPlayerIndex #

Get the player index of an opened game controller

method : public : GetPlayerIndex() ~ Int

Return

TypeDescription
Intthe player index for controller, or -1 if it's not available

GetProduct #

Get the USB product ID of an opened controller, if available

method : public : GetProduct() ~ Int

Return

TypeDescription
Intthe USB product ID, or zero if unavailable

GetProductVersion #

Get the product version of an opened controller, if available. If the product version isn't available this function returns 0.

method : public : GetProductVersion() ~ Int

Return

TypeDescription
Intthe USB product version, or zero if unavailable

GetStringForAxis # function

Convert from an SDL_GameControllerAxis enum to a string

function : GetStringForAxis(axis:GameControllerAxis) ~ String

Parameters

NameTypeDescription
axisGameControllerAxisan enum value for a given GameControllerAxis

Return

TypeDescription
Stringstring for the given axis, or Nil if an invalid axis is specified

GetStringForButton # function

Convert from an SDL_GameControllerButton enum to a string

function : GetStringForButton(button:GameControllerButton) ~ String

Parameters

NameTypeDescription
buttonGameControllerButtonan enum value for a given GameControllerButton

Return

TypeDescription
Stringa string for the given button

GetVendor #

Get the USB vendor ID of an opened controller, if available

method : public : GetVendor() ~ Int

Return

TypeDescription
Intthe USB vendor ID, or zero if unavailable

IsController # function

Check if the given joystick is supported by the game controller interface

function : IsController(joystick_index:Int) ~ Bool

Parameters

NameTypeDescription
joystick_indexIntthe device_index of a device

Return

TypeDescription
Booljoystick_index the device_index of a device

Mapping #

Get the current mapping of a Game Controller

method : public : Mapping() ~ String

Return

TypeDescription
Stringstring that has the controller's mapping or NULL if no mapping is available

Name #

Get the SDL_GameController associated with an instance id

method : public : Name() ~ String

Return

TypeDescription
Stringan SDL_GameController on success or NULL on failure

NameForIndex # function

Get the implementation dependent name for the game controller

function : NameForIndex(joystick_index:Int) ~ String

Parameters

NameTypeDescription
joystick_indexIntthe device_index of a device

Return

TypeDescription
Stringjoystick_index the device_index of a device

New # constructor

Open a game controller for use.

New(joystick_index:Int)

Parameters

NameTypeDescription
joystick_indexIntthe device_index

NumMappings # function

Get the number of mappings installed

function : NumMappings() ~ Int

Return

TypeDescription
Intthe number of mappings

Rumble #

Start a rumble effect on a game controller

method : public : Rumble(low_frequency_rumble:Int, high_frequency_rumble:Int, duration_ms:Int) ~ Int

Parameters

NameTypeDescription
low_frequency_rumbleIntThe intensity of the low frequency (left) rumble motor, from 0 to 0xFFFF
high_frequency_rumbleIntThe intensity of the high frequency (right) rumble motor, from 0 to 0xFFFF
duration_msIntThe duration of the rumble effect, in milliseconds

Return

TypeDescription
Int0, or -1 if rumble isn't supported on this controller

Update # function

Manually pump game controller updates if not using the loop.

function : Update() ~ Nil