extends Button

export var myAction = "face_up"

func _ready():
  set_process_input(false)
  var textNode = get_node("../" + myAction)
  var currentKeys = InputMap.get_action_list(myAction)
  var currentKey = currentKeys[0].as_text()
  textNode.parse_bbcode("[font=res://fonts/unlock_font_small.tres][color=red]" + currentKey + "[/color][/font]")
  
func _pressed():
  set_process_input(true)
  pass

func _input(event):
  if event is InputEventKey:
    var actionList = InputMap.get_action_list(myAction)
    for e in actionList:
      InputMap.action_erase_event(myAction, e)
    InputMap.action_add_event(myAction, event)
    var textNode = get_node("../" + myAction)
    textNode.parse_bbcode("[font=res://fonts/unlock_font_small.tres][color=red]" + event.as_text() + "[/color][/font]")
    get_tree().set_input_as_handled()
    set_process_input(false)