Window:shortcut(key, func, [ctrl], [shift], [alt]) method


Sets a new keyboard shortcut for the window.

Parameters

key

A one character string, which represents the key that will throw the shortcut's provided function.

func

A function that will be executed each time the user press the key.

[ctrl]

An optional boolean value, indicating if the CONTROL key must be pressed to fire the shortcut.

[shift]

An optional boolean value, indicating if the SHIFT key must be pressed to fire the shortcut.

[alt]

An optional boolean value, indicating if the ALT key must be pressed to fire the shortcut.

Return value

The method returns no value.

Example

local ui = require "ui" -- create a window local win = ui.Window("Window:shortcut() sample", 320, 200) -- create a label local label = ui.Label(win, "Press CTRL-X to exit...") -- prevent the window to close when pressing the window close button function win:onClose() return false end -- the CTRL-X shortcut function function close_window() win:hide() end -- set the CTRL-X shortcut win:shortcut("x", close_window, true) win:show() while win.visible do ui.update() end