Skip to content

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).

function OnKey(key, pressed)
-- ...
end
Parameter Type
key string the key’s engine name
pressed boolean true on the press, false on the release

nothing

local open = false
function OnKey(key, pressed)
if key == "f5" and pressed then
open = not open
if open then ShowUiElement("panel") else HideUiElement("panel") end
end
end

ShowUiElement · OnFrame · the The game’s UI for a script group of the index