Skip to main content

! Press a gamepad button (:press)

This method is available in versions after 20260805

Declaration​

success, err = pad:press(button [, press_delay_ms])

Parameters​

  • button
    Integer or string. See button parameters for supported numbers and names
  • press_delay_ms
    Finite non-negative number, optional. Time to hold the button, in milliseconds. Defaults to 60

Returns​

  • success
    Boolean. True if the button was pressed and released; false if the device is disconnected or busy, the target button is already held, or input delivery fails
  • err
    String. Error message when the operation fails

Description​

  • Presses and releases only the target button without changing any other buttons that are already held
  • The call fails if the target button is already held
  • press yields the current Lua execution thread while waiting for the hold time. During this period, other operations on the same gamepad return false, "hardware gamepad is busy"; different gamepad objects remain independent
  • Invalid argument types, unknown names, and out-of-range values raise Lua argument errors

Example​

local pad = assert(gamepad.connect())

assert(pad:press("a"))
assert(pad:press("menu"))
assert(pad:press(32))
assert(pad:disconnect())