Return on focused text input

There’s a text input I have and I want it so when people write on it and press enter something happens, but while this works


It also requires the user to click somewhere else, to unfocus the text input so it’s saved or something, can I make it so it doesn’t require that extra click?

1 Like

I still couldn’t do this

1 Like

You want to focus or unfocus? Ok unfocus, I will try that with javascript

Unfortunately this isn’t possible. Here’s a thread about it:

Edit: this is about how you can’t just press Enter (for example) to commit the text of an input field.

1 Like

thats very simple:

runtimeScene.getObjects("Name")[0]._renderer.input.blur()

but as @worriedpixels stated, you still cant check keypresses

1 Like

But since I love javascript, I got this code that checks if the enter key is pressed even while focusing the text input, then unfocus it.

if (objects.length > 0) {
    const renderer = objects[0]._renderer;

    document.onkeypress = function(e) {
        e = e || window.event;
        const key = e.keyCode;
        if (key === 13) {
            renderer._input.blur();
        }
    }
}
1 Like

Im super new to gdevelop and programming in general but i think i figured out a way to do this
I set my text input to a text area and essentially instead of the event being for the return button my event is if the text input contains a new line (it doesnt show it well in the screenshot but its literally typed out as
"
"
)

my intention is a command line, so when the new line event happens it sets a global text variable (CurrentCommand) to the the text inputs string and then sets the text input to be empty

you might notice that the text input will still have that animation of moving to the next line, what i did was add a text box with a event that made it copy a 2nd global text variable (CurrentText), set the text input opacity to 1 (and moved it to the side) so that the text box is what looks like its typing and made an event that made the text input be constantly focused on (so theres not an issue with the user not being able to type in the text input)