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)

asked Mar 10, 2018 in Engine by colonelkurtz (43 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_erase_event("InputMap_button",old_button[0])
 InputMap.action_add_event("InputMap_button", event)
answered Mar 11, 2018 by colonelkurtz (43 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 How to use this Q&A? before posting your first questions.