0 votes

Good time of day. I have a serious question. How to get the symbol when the key is pressed, but it does not use a LineEdit and other nodes?

in Engine by (22 points)


1 Answer

+3 votes
Best answer

You can have it done by reading the input and converting the scancodes using the built-in KEY_* constants of the global scope.

Simple code snippet would look like this:

func _ready():

func _input(event):

    if event.type == InputEvent.KEY and event.is_pressed():
        print('pressed: ' + str(event.unicode))

        if event.scancode == KEY_A:

As far as I know there's no direct way to convert scancodes to string, so you can create a dictionary like {scancode: 'string'} to convert symbols.

by (172 points)
selected by

Was such a thought, but what about the signs? If letters and numbers - it's just, the characters each keyboard is different.



I found a solution to a slightly different line.
Thanks for the help. It remains only to convert "Percent" to"%", etc.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.