Skip to main content

Joystick

Description:

  Represents a physical joystick.

type

Type: Function.

Description:

  Gets the type of the object as a string.

Signature:

type: function(self: Joystick): string

Returns:

Return TypeDescription
stringThe type as a string.

Of

Type: Function.

Description:

  Checks whether an object is of a certain type. If the object has the type with the specified name in its hierarchy, this function will return true.

Signature:

typeOf: function(self: Joystick, type_name: string): boolean

Parameters:

ParameterTypeDescription
type_namestringThe name of the type to check for.

Returns:

Return TypeDescription
booleanTrue if the object is of the specified type, false otherwise.

release

Type: Function.

Description:

  Destroys the object's Lua reference. The object will be completely deleted if it's not referenced by any other LÖVE object or thread. This method can be used to immediately clean up resources without waiting for Lua's garbage collector.

Signature:

release: function(self: Joystick): boolean

Returns:

Return TypeDescription
booleanTrue if the object was released by this call, false if it had been previously released.

isConnected

Type: Function.

Description:

  Gets whether the Joystick is connected.

Signature:

isConnected: function(self: Joystick): boolean

Returns:

Return TypeDescription
booleanTrue if the Joystick is currently connected, false otherwise.

getName

Type: Function.

Description:

  Gets the name of the joystick.

Signature:

getName: function(self: Joystick): string

Returns:

Return TypeDescription
stringThe name of the joystick.

getID

Type: Function.

Description:

  Gets the joystick's unique identifier. The identifier will remain the same for the life of the game, even when the Joystick is disconnected and reconnected, but it '''will''' change when the game is re-launched.

Signature:

getID: function(self: Joystick): integer, integer | nil

Returns:

Return TypeDescription
integerThe Joystick's unique identifier. Remains the same as long as the game is running.
integer or nilUnique instance identifier. Changes every time the Joystick is reconnected. nil if the Joystick is not connected.

getGUID

Type: Function.

Description:

  Gets a stable GUID unique to the type of the physical joystick which does not change over time. For example, all Sony Dualshock 3 controllers in OS X have the same GUID. The value is platform-dependent.

Signature:

getGUID: function(self: Joystick): string

Returns:

Return TypeDescription
stringThe Joystick type's OS-dependent unique identifier.

getDeviceInfo

Type: Function.

Description:

  Gets the USB vendor ID, product ID, and product version numbers of joystick which consistent across operating systems. Can be used to show different icons, etc. for different gamepads. Overload details:

  1. Some Linux distribution may not ship with SDL 2.0.6 or later, in which case this function will returns 0 for all the three values.

Signature:

getDeviceInfo: function(self: Joystick): integer, integer, integer

Returns:

Return TypeDescription
integerThe USB vendor ID of the joystick.
integerThe USB product ID of the joystick.
integerThe product version of the joystick.

getAxisCount

Type: Function.

Description:

  Gets the number of axes on the joystick.

Signature:

getAxisCount: function(self: Joystick): integer

Returns:

Return TypeDescription
integerThe number of axes available.

getButtonCount

Type: Function.

Description:

  Gets the number of buttons on the joystick.

Signature:

getButtonCount: function(self: Joystick): integer

Returns:

Return TypeDescription
integerThe number of buttons available.

getHatCount

Type: Function.

Description:

  Gets the number of hats on the joystick.

Signature:

getHatCount: function(self: Joystick): integer

Returns:

Return TypeDescription
integerHow many hats the joystick has.

getAxis

Type: Function.

Description:

  Gets the direction of an axis.

Signature:

getAxis: function(self: Joystick, axis: integer): number

Parameters:

ParameterTypeDescription
axisintegerThe index of the axis to be checked.

Returns:

Return TypeDescription
numberCurrent value of the axis.

getAxes

Type: Function.

Description:

  Gets the direction of each axis.

Signature:

getAxes: function(self: Joystick): number...

Returns:

Return TypeDescription
number...Direction of axis1.

getHat

Type: Function.

Description:

  Gets the direction of the Joystick's hat.

Signature:

getHat: function(self: Joystick, hat: integer): string

Parameters:

ParameterTypeDescription
hatintegerThe index of the hat to be checked.

Returns:

Return TypeDescription
stringThe direction the hat is pushed.

isDown

Type: Function.

Description:

  Checks if a button on the Joystick is pressed. LÖVE 0.9.0 had a bug which required the button indices passed to Joystick:isDown to be 0-based instead of 1-based, for example button 1 would be 0 for this function. It was fixed in 0.9.1.

Signature:

isDown: function(self: Joystick, buttons: integer...): boolean

Parameters:

ParameterTypeDescription
buttonsinteger...The index of a button to check.

Returns:

Return TypeDescription
booleanTrue if any supplied button is down, false if not.

isGamepad

Type: Function.

Description:

  Gets whether the Joystick is recognized as a gamepad. If this is the case, the Joystick's buttons and axes can be used in a standardized manner across different operating systems and joystick models via Joystick:getGamepadAxis, Joystick:isGamepadDown, love.gamepadpressed, and related functions. LÖVE automatically recognizes most popular controllers with a similar layout to the Xbox 360 controller as gamepads, but you can add more with love.joystick.setGamepadMapping. Overload details:

  1. If the Joystick is recognized as a gamepad, the physical locations for the virtual gamepad axes and buttons correspond as closely as possible to the layout of a standard Xbox 360 controller.

Signature:

isGamepad: function(self: Joystick): boolean

Returns:

Return TypeDescription
booleanTrue if the Joystick is recognized as a gamepad, false otherwise.

isGamepadDown

Type: Function.

Description:

  Checks if a virtual gamepad button on the Joystick is pressed. If the Joystick is not recognized as a Gamepad or isn't connected, then this function will always return false.

Signature:

isGamepadDown: function(self: Joystick, buttons: string...): boolean

Parameters:

ParameterTypeDescription
buttonsstring...The gamepad button to check.

Returns:

Return TypeDescription
booleanTrue if any supplied button is down, false if not.

getGamepadAxis

Type: Function.

Description:

  Gets the direction of a virtual gamepad axis. If the Joystick isn't recognized as a gamepad or isn't connected, this function will always return 0.

Signature:

getGamepadAxis: function(self: Joystick, axis: string): number

Parameters:

ParameterTypeDescription
axisstringThe virtual axis to be checked.

Returns:

Return TypeDescription
numberCurrent value of the axis.

getGamepadMapping

Type: Function.

Description:

  Gets the button, axis or hat that a virtual gamepad input is bound to. Overload details:

  1. Returns nil if the Joystick isn't recognized as a gamepad or the virtual gamepad axis is not bound to a Joystick input.
  2. The physical locations for the virtual gamepad axes and buttons correspond as closely as possible to the layout of a standard Xbox 360 controller.

Signature:

getGamepadMapping: function(self: Joystick, input: string): string | nil, integer | nil, string | nil

Parameters:

ParameterTypeDescription
inputstringThe virtual gamepad axis to get the binding for. Depending on the overload: The virtual gamepad button to get the binding for.

Returns:

Return TypeDescription
string or nilThe type of input the virtual gamepad axis is bound to. Depending on the overload: The type of input the virtual gamepad button is bound to.
integer or nilThe index of the Joystick's button, axis or hat that the virtual gamepad axis is bound to. Depending on the overload: The index of the Joystick's button, axis or hat that the virtual gamepad button is bound to.
string or nilThe direction of the hat, if the virtual gamepad axis is bound to a hat. nil otherwise. Depending on the overload: The direction of the hat, if the virtual gamepad button is bound to a hat. nil otherwise.

getGamepadMappingString

Type: Function.

Description:

  Gets the full gamepad mapping string of this Joystick, or nil if it's not recognized as a gamepad. The mapping string contains binding information used to map the Joystick's buttons an axes to the standard gamepad layout, and can be used later with love.joystick.loadGamepadMappings.

Signature:

getGamepadMappingString: function(self: Joystick): string | nil

Returns:

Return TypeDescription
string or nilA string containing the Joystick's gamepad mappings, or nil if the Joystick is not recognized as a gamepad.

isVibrationSupported

Type: Function.

Description:

  Gets whether the Joystick supports vibration. Overload details:

  1. The very first call to this function may take more time than expected because SDL's Haptic / Force Feedback subsystem needs to be initialized.

Signature:

isVibrationSupported: function(self: Joystick): boolean

Returns:

Return TypeDescription
booleanTrue if rumble / force feedback vibration is supported on this Joystick, false if not.

setVibration

Type: Function.

Description:

  Sets the vibration motor speeds on a Joystick with rumble support. Most common gamepads have this functionality, although not all drivers give proper support. Use Joystick:isVibrationSupported to check.

Signature:

setVibration: function(self: Joystick): boolean

Returns:

Return TypeDescription
booleansuccess — True if the vibration was successfully applied, false if not.

setVibration

Type: Function.

Description:

  Sets the vibration motor speeds on a Joystick with rumble support. Most common gamepads have this functionality, although not all drivers give proper support. Use Joystick:isVibrationSupported to check.

Signature:

setVibration: function(self: Joystick, left: number, right?: number, duration?: number): boolean

Parameters:

ParameterTypeDescription
leftnumberStrength of the left vibration motor on the Joystick. Must be in the range of 1.
rightnumberStrength of the right vibration motor on the Joystick. Must be in the range of 1.
durationnumberThe duration of the vibration in seconds. A negative value means infinite duration. (Default: -1.)

Returns:

Return TypeDescription
booleanTrue if the vibration was successfully disabled, false if not.

getVibration

Type: Function.

Description:

  Gets the current vibration motor strengths on a Joystick with rumble support.

Signature:

getVibration: function(self: Joystick): number, number
getConnectedIndex: function(self: Joystick): integer | nil

Returns:

Return TypeDescription
number or integer or nilCurrent strength of the left vibration motor on the Joystick.
numberCurrent strength of the right vibration motor on the Joystick.