Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I keybind a textbox with the enter key?

I'm trying to make a scripting command bar that can be used in game. (To elaborate, a textbox, that when someone enters Lua code into it and pushes enter, that code will run.) I came up with a working version.

Originally, the user would have to click out of the text box and then push enter, due to the fact that I used the KeyUp event of Mouse, and therefore, the event wouldn't fire while the user is focused on the text box. Recently, I discovered an event of text box called InputChanged, which is supposed to detect things like keyboard inputs even when the user is focused on the TextBox. I tried it, but it didn't fire whenever I pushed the enter key. My code, where script.Parent is a TextBox:

script.Parent.InputChanged:connect(function(input)
	local key = input.KeyCode
	if key == "Return" then
		script.Parent.Update.Value = true
		wait(.1)
		script.Parent.Update.Value = false
	end
end)

How would I bind the enter key to the TextBox, even when the user is focused on it. If not this event, then is there another that I should use?

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.