0 votes

Does GDScript have a simple function or command that can display a readable version of whatever key/mouse button is mapped to an InputMap? For example, "ui_up" has 'Up' and a Joypad button assigned to it, and using InputMap.get_action_list("ui_up") gives me: [[InputEventKey:26], [InputEventJoypadButton:27]]

If I displayed that in a controls setting screen, I don't think anyone would know what it means.

Related to that, I've been trying to set a new input for an existing InputMap. Input doesn't have any get key press that I could use to read whatever the user presses, nor does InputEvent. I see InputMap has settings for removing and adding actions, but I'm not sure how to get a user action to set in InputMap.action_add_event("button", new_event)

in Engine by (44 points)

1 Answer

0 votes
Best answer

Figured it out with some help:

event.as_text() shows the text for an event. For mouse button input, this shows quite a bit of info, and I found thatevent.button_index gives better results, though requires another step to convert numbers (number index of mouse buttons) to names like LMB, RMB, etc.

To get key presses and replace the current input map with the new key:

if event is InputEventKey and event.pressed:
 var old_button= InputMap.get_action_list("InputMap_button")
 InputMap.action_add_event("InputMap_button", event)
by (44 points)
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 Frequently asked questions and 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 [email protected] with your username.