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 https://docs.godotengine.org/en/stable/classes/class_inputevent.html#class-inputevent
{
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
}
}