Files
godot-demo-projects/gui/input_mapping/ActionRemapButton.gd
Voylin 85e7aeec99 Fixed GUI Input Mapping Demo Script Errors for 4.0-dev
Edited the project settings to match the new Godot 4 standard and fixed
the script errors which were making it impossible to run this demo.

Now everything works properly for the 4.0-dev version.

Changed to Vulkan Mobile + Changed argument name

Followed the suggestions of aaronfranke
Changed viewport size
2022-04-03 14:21:54 +09:00

36 lines
809 B
GDScript

extends Button
@export var action: String = "ui_up"
func _ready():
assert(InputMap.has_action(action))
set_process_unhandled_key_input(false)
display_current_key()
func _toggled(is_button_pressed):
set_process_unhandled_key_input(is_button_pressed)
if is_button_pressed:
text = "... Key"
release_focus()
else:
display_current_key()
func _unhandled_key_input(event):
# Note that you can use the _input callback instead, especially if
# you want to work with gamepads.
remap_action_to(event)
button_pressed = false
func remap_action_to(event):
InputMap.action_erase_events(action)
InputMap.action_add_event(action, event)
text = "%s Key" % event.as_text()
func display_current_key():
var current_key = InputMap.action_get_events(action)[0].as_text()
text = "%s Key" % current_key