Skip to main content

Hold down a gamepad button (:down)

This method is available in versions after 20260805

Declaration

success, err = pad:down(button)

Parameters

  • button Integer or string. An integer from 1 through 32, one of the names below, or "start" or "menu"; string matching is case-insensitive
NumberButton nameAliases
1a-
2b-
3x-
4y-
5left_shoulderleft_bumper, lb, l1
6right_shoulderright_bumper, rb, r1
7left_triggerlt, l2
8right_triggerrt, r2
9left_stickl3
10right_stickr3
11l4left_paddle
12r4right_paddle
13m1-
14m2-
15m3-
16m4-

Returns

  • success Boolean. True if the operation succeeds; false if the device is disconnected or busy, or if input delivery fails
  • err String. Error message when the operation fails

Description

  • Numeric values 1 through 32 identify numeric buttons rather than button codes standardized across devices. Prefer the names in the table when possible
  • Numeric buttons 17 through 32 have no predefined names and only have an effect when the target app supports the corresponding extended buttons
  • "start" and "menu" are aliases for the same menu input and do not correspond to a numeric button from 1 through 32
  • The names select, back, options, home, share, and touchpad buttons are not currently supported
  • left_trigger and right_trigger support only pressed or released states, not analog pressure. menu does not trigger the system Home action
  • Invalid argument types, unknown names, and out-of-range values raise Lua argument errors instead of returning false, error

Example

local pad = assert(gamepad.connect())

assert(pad:down("left_shoulder"))
assert(pad:up("left_shoulder"))
assert(pad:down(13)) -- numeric button 13
assert(pad:up(13))
assert(pad:disconnect())