(SOLVED) Is it possible to understand what the particular key was pressed in InputEvent?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MarkKorvin

I am trying to implement the dialog system and I want to choose my dialog options using keyboard’s numericals keys (e.g 1,2,3…). I can create an InputEvent for every number or I can handle ten InputEventKeys manually but it looks strange because the logic for every event is the same.

What I want is to unite those events into one InputEvent group, parse the particular key that was pressed and use it as a variable for my function. Is it even possible in Godot? I cannot find any appropriate method in the official documentation InputEvent — Godot Engine (stable) documentation in English

   {
        if (@event.IsActionPressed("numerical")) {
            // I want to do smth like this
            InputEventKey key = @event.GetKey() 
            DoSmth(key)
    }

Edit:
My final solution below. Thanks to Gluon for the hint about scancodes. More information can be found here

// 'numeric' includes keys from '1' to '9'

if (@event.IsActionPressed("numeric")) {
    if (@event is InputEventKey eventKey) {
        DoSmth(eventKey.Scancode - 48);  // Scancode of '1' is 49
    }
}
:bust_in_silhouette: Reply From: Gluon

The only way I know of personally is using scancodes so if you hav esomething like this

func _input(event):
    (print(event.scancode))

then this will print out the scancode of the button pressed. Scancodes can be seen here,

but that isnt human readable. Someone else may have a better way but given you havent had an answer yet I thought I would at least give you this idea.

That’s perfect, thank you! It doesn’t matter that scancodes unreadable, much more important is that they are ordered. I’ve updated my post with the final solution

MarkKorvin | 2022-12-27 22:55