How do I rebind keybinds from a string

var bigString: Array = ["InputEventKey: keycode=87 (W), mods=none, physical=true, pressed=false, echo=false", "InputEventKey: keycode=4194320 (Up), mods=none, physical=true, pressed=false, echo=false"]
for input in bigString:
    var inputString = input.replace('InputEventKey: ', '')
    var inputRawArray = inputString.split(",")
    var inputArray = []
    for inputItem in inputRawArray:
        if inputItem.begins_with("keycode"):
            # We finally filtered out everything but the actual keycode
            var keycode = inputItem.replace('keycode=', '')

            # Create InputEventKey, set the keycode, add it to InputMap
            var keyEvent = InputEventKey.new()
            keyEvent.keycode = int(keycode)
            # InputMap.add_action("up") <- Only if it does not yet exist
            InputMap.action_add_event("up",keyEvent)

This is untested and super messy hacky pseudocode.
If this works then maybe it’s also relevant for the author of Save in to input map through keycode? - #2 by militaryg @militaryg


Referencing and research:

2 Likes