- Edited
kuligs2 Here's an "educational" version for easier understanding:
class_name CheatCodeCapture extends Node
signal cheat_code_entered(name: String)
var action_sequence: String
var cheatcodes: Dictionary = {"ui_left ui_right" : "cheat1"}
func _input(event):
# iterate through actions defined in input map
for action in InputMap.get_actions():
if event.is_action_pressed(action):
# accumulate actions
if not action_sequence.is_empty():
action_sequence += " " # insert space between actions
action_sequence += action
# check if the current action sequence is present in any of cheatcodes
for code in cheatcodes.keys():
if action_sequence.contains(code):
# action sequence found, emit the signal and clear the accumulated sequence
cheat_code_entered.emit(cheatcodes[code])
action_sequence = ""
break