Skip to content

OnTextInput

A character was typed while the script has the keyboard.

For a text field of the script’s own - a name, a password: the character as the player’s keyboard layout makes it (a German keyboard’s Z is a Z here, while OnKey names the key at that place y), with Shift and the layout’s accents applied, as UTF-8. It comes only while the script holds the keyboard (SetKeyboardCapture), next to the key’s own OnKey; Enter, Backspace, Esc and Tab come as keys alone.

function OnTextInput(text)
-- ...
end
Parameter Type
text string the character typed (UTF-8)

nothing

local chars = {} -- one entry per character: Backspace takes a whole one, whatever its bytes
function OnTextInput(text)
if #chars < 24 then chars[#chars + 1] = text SetUiText("field", table.concat(chars)) end
end
function OnKey(key, pressed)
if pressed and key == "backspace" then table.remove(chars) SetUiText("field", table.concat(chars)) end
end

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