Say for an example if you want to get a key mapped to an action to report to the player what key to press(maybe your game has input remapping supported in options so you can't hard code what to print to the player) you would use the InputMap
to do so.
interact_event_binding = InputMap.get_action_list("use_interact") #get_action_list doesn't get a list of actions but a list of keys mapped to the specified action as an array
InfoLabel.set_text("Press " + interact_event_binding[0].as_text() + " to use") #note that we are accessing interact_event_binding as an array and picking the first element in the array here, first being index 0
In response to the info given to the player by the label player presses key triggering our "use_interact"
action:
func _input(event: InputEvent) -> void:
if event.is_action_pressed("use_interact"):
#Do something in response to the action triggered by the key reported in above example
InfoLabel.set_visible(false)
Not sure if that is exactly what you are trying to do but maybe a useful example of what can be done. As for
@AnarcoPhysic said:
func _input(event):
if event is InputEventAction: #this test ever seems to result false !
# I can get the name of the Action
match event.action:
"my_action_name":
#do things
"my_another_action_name":
#do other actions
perhaps try
if event is InputEvent:
print("an input event was triggered")
print("the triggered event is " + event.as_text())
instead? edit: no that still gives us the mapped key...
if event is InputEvent:
print("an input event was triggered")
if InputMap.event_is_action(event, "use_interact"):
print("the triggered event is action use_interact")
works to check if event is a specific action though
edit 2: oh wow is match a mess to use. And apparently slower than multiple if statements.