0 votes

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.

Godot version v3.3.4
in Engine by (52 points)

1 Answer

+1 vote
Best answer

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

by (57 points)
selected by

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++){
                if(@event.IsAction(ActionList[i].ToString())){
                    CurrentAction = ActionList[i].ToString();
                }
}
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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.