Difference between revisions of "love.gamepadpressed"

(Created page)
 
(Example: print the MRU gamepad name)
 
(2 intermediate revisions by 2 users not shown)
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 ==
Line 18: Line 35:
 
[[Category:Callbacks]]
 
[[Category:Callbacks]]
 
{{#set:Description=Called when a Joystick's virtual gamepad button is pressed.}}
 
{{#set:Description=Called when a Joystick's virtual gamepad button is pressed.}}
 +
{{#set:Subcategory=Joystick}}
 +
{{#set:Since=090}}
 +
 
== Other Languages ==
 
== Other Languages ==
 
{{i18n|love.gamepadpressed}}
 
{{i18n|love.gamepadpressed}}

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