! Create an independent hardware keyboard (key.connect_keyboard)
This function is available in versions after 20260805
Declaration
keyboard, err = key.connect_keyboard([properties])
Parameters
- properties Table. Optional. Sets the following commonly used device properties; the values shown are used by default when omitted:
{
VendorID = 0x5858,
ProductID = 0x0001,
Product = "XXTouch Keyboard",
Manufacturer = "XXTouch",
Transport = "USB",
}
You may also set VersionNumber, SerialNumber, and LocationID. Other properties are not guaranteed to take effect.
Returns
- keyboard
Hardware keyboard object. Returns
nilif creation fails. - err String. Error message returned when creation fails.
On failure, the two return values are nil, error.
Description
Creates an independent hardware keyboard object. Each object has its own key state and connection lifecycle. Waiting for the connection may yield; other threads may run before the function returns.
Transportonly affects how iOS or the target app identifies the keyboard. Setting it to"Bluetooth"or"BluetoothLowEnergy"does not create a Bluetooth connection, advertise or pair the device, or make it appear in another device's Bluetooth list- At most six non-modifier keys can be held at once; modifier keys do not count toward this limit. Release some keys before adding more
- The target app may be unable to distinguish which hardware keyboard object produced the input
- This function creates only an independent object and does not change the existing
key.*APIs. Usekey.connect_global_keyboardfor that behavior - Failed input is not retried through another input method
Example
local keyboard, err = key.connect_keyboard({
Product = "XXTouch Keyboard",
})
assert(keyboard, err)
assert(keyboard:press("a"))
assert(keyboard:down("LEFTSHIFT"))
assert(keyboard:press("b"))
assert(keyboard:up("LEFTSHIFT"))
assert(keyboard:send_text("Hello"))
keyboard:disconnect()