Skip to content

OnKey

A key was pressed or released.

The keys come as the engine names them (f, enter, space, lalt, 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). A press always gets its release, even when something else takes the key in between (the cursor key held, a server page that took the keyboard) or the game window loses the focus. Nothing typed into a server page or the chat box comes here. The mouse buttons are OnMouseButton’s; IsKeyDown asks whether a key is held right now.

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