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?

asked Jul 29, 2017 in Engine by Timofffee (22 points)

Input.iskeypressed(key_tag)?

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():
    set_process_input(true)

func _input(event):

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

        if event.scancode == KEY_A:
            print('AHA!')

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.

answered Jul 30, 2017 by Dr_TwiSteD (170 points)
selected Jul 31, 2017 by Timofffee

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

Okay!

OS.get_scancode_string(event.unicode)

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.