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.

Joystick

Handles inputs from joysticks

Operations

CurrentPowerLevel #

Get the battery level of a joystick as JoystickPowerLevel

method : public : CurrentPowerLevel() ~ JoystickPowerLevel

Return

TypeDescription
JoystickPowerLevelcurrent battery level as JoystickPowerLevel on success or SDL_JOYSTICK_POWER_UNKNOWN

Free #

Close joystick previously opened

method : public : Free() ~ Nil

FromInstanceID # function

Get the Joystick associated with an instance id.

function : FromInstanceID(instance_id:Int) ~ Joystick

Parameters

NameTypeDescription
instance_idIntthe instance id to get the SDL_Joystick for

Return

TypeDescription
Joystickinstance_id the instance id to get the SDL_Joystick for

GetAxisInitialState #

Get the initial state of an axis control on a joystick

method : public : GetAxisInitialState(axis:Int, state:IntRef) ~ Bool

Parameters

NameTypeDescription
axisIntthe axis to query; the axis indices start at index 0
stateIntRefUpon return, the initial value is supplied here

Return

TypeDescription
Booltrue if this axis has any initial value, or false if not

GetDeviceInstanceID # function

Get the instance ID of a joystick

function : GetDeviceInstanceID(device_index:Int) ~ Int

Parameters

NameTypeDescription
device_indexIntthe index of the joystick to query (the N'th joystick on the system

Return

TypeDescription
Intthe instance id of the selected joystick. If called on an invalid index, this function returns zero

GetDeviceProduct # function

Get the USB product ID of a joystick, if available

function : GetDeviceProduct(device_index:Int) ~ Int

Parameters

NameTypeDescription
device_indexIntthe index of the joystick to query (the N'th joystick on the system

Return

TypeDescription
Intthe USB product ID of the selected joystick. If called on an invalid index, this function returns zero

GetDeviceProductVersion # function

Get the product version of a joystick, if available

function : GetDeviceProductVersion(device_index:Int) ~ Int

Parameters

NameTypeDescription
device_indexIntthe index of the joystick to query (the N'th joystick on the system

Return

TypeDescription
Intthe product version of the selected joystick. If called on an invalid index, this function returns zero

GetDeviceType #

Get the type of a joystick, if available

method : public : GetDeviceType(device_index:Int) ~ JoystickType

Parameters

NameTypeDescription
device_indexIntthe index of the joystick to query (the N'th joystick on the system

Return

TypeDescription
JoystickTypethe SDL_JoystickType of the selected joystick. If called on an invalid index

GetDeviceVendor #

Get the USB vendor ID of a joystick, if available

method : public : GetDeviceVendor(device_index:Int) ~ Int

Parameters

NameTypeDescription
device_indexIntthe index of the joystick to query (the N'th joystick on the system

Return

TypeDescription
Intthe USB vendor ID of the selected joystick. If called on an invalid index, this function returns zero

GetName #

Get the implementation dependent name of a joystick

method : public : GetName() ~ String

Return

TypeDescription
Stringname of the selected joystick. If no name can be found, this function returns NULL,

GetProduct #

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

method : public : GetProduct() ~ Int

Return

TypeDescription
Intthe product version of the selected joystick, or 0 if unavailable.

GetProductVersion #

Get the product version of an opened joystick, if available

method : public : GetProductVersion() ~ Int

Return

TypeDescription
Intthe firmware version of the selected joystick, or 0 if unavailable

GetType #

Get the type of an opened joystick

method : public : GetType() ~ JoystickType

Return

TypeDescription
JoystickTypethe JoystickType of the selected joystick

GetVendor #

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

method : public : GetVendor() ~ Int

Return

TypeDescription
Intthe USB vendor ID of the selected joystick, or 0 if unavailable

IsNull #

Determines if the underlying SDL C-struct is NULL

method : public : IsNull() ~ Bool

Return

TypeDescription
Booltrue if NULL, false otherwise

New # constructor

Open a joystick for use

New(device_index:Int)

Parameters

NameTypeDescription
device_indexIntindex of the joystick to query

Number # function

Count of the number of joysticks attached to the system

function : Number() ~ Int

Return

TypeDescription
Intnumber of attached joysticks on success or a negative error code on failure