Skip to main content

! Type text with a hardware keyboard (:send_text)

This method is available in versions after 20260805

Declaration

success, err = keyboard:send_text(text[, type_delay_ms, shift_delay_ms])

Parameters

  • text String. Text to type. Only English letters, digits, spaces, half-width symbols, and escape sequences "\b", "\r", and "\t" are supported.
  • type_delay_ms Number. Optional. Delay between key operations in milliseconds. Default: 0.
  • shift_delay_ms Number. Optional. Delay around pressing or releasing Shift in milliseconds. Default: 0.

Returns

  • success Boolean. Returns true after all text is sent successfully and false on failure.
  • err String. Error message returned when sending fails.

Description

Generate key and Shift combinations using the current Lua US keyboard mapping. Waiting during input may yield; other threads may run before the method returns.

  • The resulting characters are still affected by the target system's keyboard layout.
  • This method preserves ordinary keys and modifier keys that were already held before the call.
  • If the same hardware keyboard is already running a :press or :send_text sequence, the new operation returns false, "hardware keyboard is busy".
  • Failed input is not retried through another input method.

Example

local keyboard = assert(key.connect_keyboard())

assert(keyboard:send_text("Hello"))
assert(keyboard:send_text("Hello", 30, 10))

assert(keyboard:disconnect())