Getting the name of the action pressed for displaying the current action (C#)

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

I have several Input Actions defined in my program. I have inputs from the mouse, keyboard and a connected Nintendo switch controller. Is there a way, within the code, besides the IsAction method for every single action to get the string for the name of the action just pressed? As you can imagine with such a large number of actions, it will be tedious to do that for every individual action I’ve defined. For example, if the action “exit” is pressed, I want to get the string “exit” and if I have another action called “forward” i want the string “forward” to be obtained the same way the string “exit” was obtained.

:bust_in_silhouette: Reply From: sunDalik

You can iterate through the list of actions (InputMap.GetActions()) and check for IsAction in the loop

Thanks for the help! For anyone else interested, here’s the c# code I made to do that, it should be in the _Input function in order to use the IsAction() method:

String CurrentAction = "Empty";
Godot.Collections.Array ActionList = InputMap.GetActions();
for(int i = 0; i < InputMap.GetActions().Count; i++){
                    CurrentAction = ActionList[i].ToString();

wooshuwu | 2022-05-11 20:15