Skip to main content

Hold down a hardware keyboard key (:down)

This method is available in versions after 20260805

Declaration

success, err = keyboard:down(key)
success, err = keyboard:down(usage_page, usage_id)

Parameters

  • key String. Uses the same key-name mapping as key.press.
  • usage_page Integer. Hardware keyboard objects currently accept only Keyboard/Keypad Usage Page 0x07.
  • usage_id Integer. Physical key identifier, not a character encoding.

Returns

  • success Boolean. Returns true when the key is held successfully and false on failure.
  • err String. Error message returned when sending fails.

Description

Hold down a hardware keyboard key. Call the corresponding :up afterwards to release it.

  • If the same keyboard is running a :press or :send_text sequence, this method returns false, "hardware keyboard is busy".
  • At most six non-modifier keys can be held at once; modifier keys do not count toward this limit.
  • On failure, the method returns false and an error message. It is not retried through another input method.

Example

local keyboard = assert(key.connect_keyboard())

assert(keyboard:press(0x07, 4)) -- Keyboard A
assert(keyboard:down(0x07, 0xE1)) -- Left Shift
assert(keyboard:up(0x07, 0xE1))

assert(keyboard:disconnect())