keyboard.bind(key, callback)function
Binds a key to a Lua callback function, called each time the specified key is pressed.
Parameters
key
A string or number representing the key to wait for. See the list of supported key codes
callback
A function that will be called each time the specified key is pressed. The callback receives three boolean arguments: isshift, iscontrol, and isalt.
Return value
This function returns a Task executed in background.
Example
--! luart-extensions
import 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)
await win:showasync()