OnKey
A key was pressed or released.
The keys come as the engine names them (f, enter, space, mouse1, f5 …) with true on the press and false
on the release; the game keeps them - a script watches, it never takes a key from the game, unless it took the whole
keyboard with SetKeyboardCapture. The keys are forwarded only while a script defines this callback (or has the
keyboard).
Syntax
Section titled “Syntax”function OnKey(key, pressed) -- ...end| Parameter | Type | |
|---|---|---|
key |
string | the key’s engine name |
pressed |
boolean | true on the press, false on the release |
Returns
Section titled “Returns”nothing
Example
Section titled “Example”local open = falsefunction OnKey(key, pressed) if key == "f5" and pressed then open = not open if open then ShowUiElement("panel") else HideUiElement("panel") end endendSee also
Section titled “See also”ShowUiElement · OnFrame · the The game’s UI for a script group of the index
