Skip to content

SetKeyboardCapture

Takes the keyboard for a menu of the script’s own - or gives it back.

While it is on, every key goes to OnKey and the game takes no input: the player neither walks nor turns the view, Esc does not open the game’s menu (it is the script’s, to close its own with), Enter does not open the chat nor its scroll keys move it, the emote wheel and the scoreboard wait. F9 stays the overlay’s. The keyboard comes back with false, when the server replaces the scripts, and when the session ends - so a script that forgets cannot keep a player from their keys for good; a script whose OnKey fails gives it back at once. The player can take it back too: Esc pressed three times within two seconds ends the capture whatever the script does (the third press does not reach OnKey), so keep a way to close your own menu on the first Esc. Keys held down at the moment it is taken are let go first.

SetKeyboardCapture(on)
Parameter Type
on boolean true takes the keyboard, false gives it back

nothing

function openMenu()
SetKeyboardCapture(true)
CreateUiText("title", 60, 60, "Choose your look", COLOR_GOLD, 1.2)
end
function OnKey(key, pressed)
if pressed and key == "escape" then ClearUi() SetKeyboardCapture(false) end
end

IsKeyboardCaptured · OnKey · the The game’s UI for a script group of the index