31 lines
655 B
GDScript3
31 lines
655 B
GDScript3
|
extends Button
|
||
|
|
||
|
@export var input_action_name : String
|
||
|
|
||
|
# Called when the node enters the scene tree for the first timde.d
|
||
|
func _ready():
|
||
|
set_process_unhandled_key_input(false)
|
||
|
pass
|
||
|
|
||
|
func _unhandled_key_input(event):
|
||
|
remap_key(event)
|
||
|
pass
|
||
|
|
||
|
|
||
|
func display_key ():
|
||
|
text = "%s" % InputMap.action_get_events(input_action_name)[0].as_text()
|
||
|
pass
|
||
|
|
||
|
func remap_key(event):
|
||
|
InputMap.action_erase_events(input_action_name)
|
||
|
InputMap.action_add_event(input_action_name, event)
|
||
|
|
||
|
text = "%s" % event.as_text()
|
||
|
pass
|
||
|
|
||
|
func _on_toggled(button_pressed):
|
||
|
set_process_unhandled_key_input(button_pressed)
|
||
|
if button_pressed: text = "..."
|
||
|
else: display_key()
|
||
|
pass
|