Check keypresses whileText Input has focus

It would be useful if when the text input has focus, if the keys could still be read with the keyboard conditions and expressions. There are times when you would like to know when keys like return is pressed.

If that’s not possible or practical then it would be helpful to have a condition like enter key was just pressed So, text like an answer can be checked without having to click a submit button or switch between the keyboard and the mouse.

When you submit text especially multiple texts in rapid repetition, it’s much easier to just hit enter than to click a button.

5 Likes

Yeah, I stopped using the text input because of this (and other things) I thought about a workaround of making a custom “key pressed” condition by checking the last character of the text input, but I have no idea of how to do it for special keys (Esc, enter etc)

1 Like

+1 from me. I like the idea of a game completely played with keyboard (no mouse), where the player enters words that the game then assesses. So if the player is near a chest, a text input box appears and the player can press Enter to get focus, type ‘open’, and then Enter again to submit the word. But instead the player has to keep reaching for a mouse just to click a ‘submit’ button. I can already see the player feedback: “Why can’t I submit my words with the Enter button like on a website? The controls are clunky.”

4 Likes

I got this javascript code that checks if the enter key is pressed and unfocus the text, just change the key code from 13 to anything else you want to check.

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();
        }
    }
}
2 Likes