Notes
- To cancel the key binding, use the Task:cancel() method.
keyboard.bind(key)
Binds a key to a Lua callback function, called each time the specified key is pressed.
The callback function will receive three boolean
parameters in the following order :
isshift
: set to true
if the SHIFT key is pressed simultaneously.iscontrol
: set to true
if the CONTROL key is pressed simultaneously.isalt
: set to true
if the MENU key is pressed simultaneously.Parameters
key
Astring
or number
representing the key to wait for. See the list of supported key codes.
Return value
This function returns a Task executed in background.Example
local ui = require "ui"
local kb = require "keyboard"
local win = ui.Window("Press the A key !", 320, 200)
local lbl = ui.Label(win, "")
local function onAPressed(isshift, iscontrol, isalt)
local isshift = isshift and " + SHIFT" or ""
local iscontrol = iscontrol and " + CONTROL" or ""
local isalt = isalt and " + ALT" or ""
lbl.text = "A"..isshift..iscontrol..isalt
lbl:center()
ui.update()
sleep(500)
lbl.text = ""
end
kb.bind("A", onAPressed)
ui.run(win):wait()