Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I keybind a textbox with the enter key?

Asked by
Minifig77 190
10 years ago

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

Log in to vote
0
Answered by 4 years ago

I know that this post is old and you may have already found a solution to this, but for those others who are wanting to find a solution to this problem, there is an event TextBox.FocusLost which returns the cause of the textbox going out of focus e.g. Enter key pressed.

Examples of this can be found on the API https://developer.roblox.com/en-us/api-reference/event/TextBox/FocusLost

Ad

Answer this question