Difference between revisions of "love.gamepadpressed"

(See Also)
(Example: print the MRU gamepad name)
 
Line 11: Line 11:
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.
 +
 +
== Example: print the MRU gamepad name ==
 +
Track the most recently used gamepad and print its name when it changes. See also [[love.joystick.getGamepadMappingString]] for more detailed names; especially when using [[love.joystick.loadGamepadMappings]].
 +
 +
<source lang="lua">
 +
local active_joystick
 +
function love.gamepadpressed(joystick, button)
 +
    if joystick == active_joystick then
 +
        return
 +
    end
 +
    active_joystick = joystick
 +
    local name = joystick:getName()
 +
    local index = joystick:getConnectedIndex()
 +
    print(string.format("Changing active gamepad to #%d '%s'.", index, name))
 +
end
 +
</source>
 +
  
 
== See Also ==
 
== See Also ==

Latest revision as of 01:19, 31 December 2021

Available since LÖVE 0.9.0
This function is not supported in earlier versions.

Called when a Joystick's virtual gamepad button is pressed.

Function

Synopsis

love.gamepadpressed( joystick, button )

Arguments

Joystick joystick
The joystick object.
GamepadButton button
The virtual gamepad button.

Returns

Nothing.

Example: print the MRU gamepad name

Track the most recently used gamepad and print its name when it changes. See also love.joystick.getGamepadMappingString for more detailed names; especially when using love.joystick.loadGamepadMappings.

local active_joystick
function love.gamepadpressed(joystick, button)
    if joystick == active_joystick then
        return
    end
    active_joystick = joystick
    local name = joystick:getName()
    local index = joystick:getConnectedIndex()
    print(string.format("Changing active gamepad to #%d '%s'.", index, name))
end


See Also



Other Languages