I have this string with the contents: ["InputEventKey: keycode=87 (W), mods=none, physical=true, pressed=false, echo=false", "InputEventKey: keycode=4194320 (Up), mods=none, physical=true, pressed=false, echo=false"]
as a variable called loaded data
how can i go about using this string in the event of InputMap.action_add_event("up",event)
I would first try to convert the String into a working and functional Dictionary although it will be difficult because the content of the String are not formatted in a uniform matter.
We essentially got a big array with only one string entry.
Also sometimes they use :, sometimes they also use =. Is there a way to uniform the entries?
For all intentions and purposes, you only need the keycode and the event_id.
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)
thank you so much for helping me with this
i spent days failing to set permanent keybinds
the closest i got is having loaded_data = loaded_data[0]
since it would be equal to the parameters i used to set it
but it didn’t work thanks to it being a string
I believe the first step would be to somehow filter out the big string to only have the important bits (keycode).
if you are somehow able to receive the input in a more workable state, then lots of the hacky code will disappear. If not, then we will have to pick our way through the raw input data, which makes things more complex and error-prone