Skip to main content

! Connect a global hardware keyboard (key.connect_global_keyboard)

This function is available in versions after 20260805

Declaration​

keyboard, err = key.connect_global_keyboard([properties])

Parameters​

  • properties
    Table. Optional. Uses the same default properties and constraints as key.connect_keyboard.

Returns​

  • keyboard
    Hardware keyboard object. Returns nil if the connection fails.
  • err
    String. Error message returned when the connection fails.

On failure, the two return values are nil, error.

Description​

Create and connect the global hardware keyboard. Waiting for the connection may yield; other threads may run before the function returns.

  • After connection, standard keyboard and keypad input from key.press, key.down, key.up, key.send_text, and key(...):press/down/up uses this object
  • Media and vendor-defined keys keep their previous behavior
  • When no global hardware keyboard is connected, the existing APIs behave as before.
  • A key.down call remains paired with its matching key.up even if the connection changes between the calls, preventing duplicate input or an incorrect release
  • Only one global hardware keyboard may be connected at a time. Calling this function again while a connection is in progress or while a global keyboard is already connected returns a failure.

Example​

local keyboard, err = key.connect_global_keyboard({
Product = "XXTouch Keyboard",
})
assert(keyboard, err)

key.press("A")
key.send_text("Hello")

local current = key.get_global_keyboard()
assert(current == keyboard)

assert(key.disconnect_global_keyboard())