Skip to content

Instantly share code, notes, and snippets.

@sert121
Created April 20, 2025 21:32
Show Gist options
  • Save sert121/d0151a294b96f79da7b6591088e9f750 to your computer and use it in GitHub Desktop.
Save sert121/d0151a294b96f79da7b6591088e9f750 to your computer and use it in GitHub Desktop.
with open("events.log", "r") as file:
content = file.read()
command_key = "Command"
shift_key = "Shift"
control_key = "Control"
alt_key = "Alt"
windows_key = "Windows"
capital_mode = False
map_key_to_toggle = {
"MetaLeft": "cmd_toggle",
"MetaRight": "cmd_toggle",
"ShiftLeft": "shift_toggle",
"ShiftRight": "shift_toggle",
"ControlLeft": "ctrl_toggle",
"ControlRight": "ctrl_toggle",
"AltLeft": "alt_toggle",
"AltRight": "alt_toggle",
"SuperLeft": "windows_toggle",
"SuperRight": "windows_toggle",
}
toggles = {
"ctrl_toggle": False,
"shift_toggle": False,
"alt_toggle": False,
"cmd_toggle": False,
"windows_toggle": False
}
typing_mode = False
drag_start = None
active_toggle = None
current_typed_word = []
new_map = []
base_time = 0
for line in content.split("\n"):
if line == "":
continue
first_part = line.split("}:")[0]
time_stamp = first_part.split("{")[-1]
time_stamp.replace("}", "")
time_checkpoint = time_stamp.split(",")[0]
differential = time_stamp.split(",")[1].split(":")[-1].strip()
time_checkpoint = time_checkpoint.split(":")[-1].strip()
time_checkpoint = float(time_checkpoint) + float(differential)/ 1000000000
second_part = line.split("}:")[1]
print(second_part)
event_base, event_key = second_part.split()[0], second_part.split()[1]
if event_base == "KeyPress": # starting a new action
key = event_key
# if its any of the toggle keys, then toggle the key
if key in map_key_to_toggle:
toggles[map_key_to_toggle[key]] = True
active_toggle = map_key_to_toggle[key]
#if its non toggle key but toggle is true
for t in toggles:
# basically check if the toggle name and val is true
if t == "cmd_toggle" and toggles[t] and key.startswith("Key"):
actual_key = key[3:]
if actual_key not in map_key_to_toggle.keys():
new_map.append([(time_checkpoint, f"Command + {actual_key}")]) # could have a custom map for copy, paste etc as well later
continue
if t == "shift_toggle" and toggles[t] and key.startswith("Key"):
actual_key = key[3:]
if actual_key not in map_key_to_toggle.keys():
new_map.append([(time_checkpoint, f"Shift + {actual_key}")])
continue
if t == "ctrl_toggle" and toggles[t] and key.startswith("Key"):
actual_key = key[3:]
if actual_key not in map_key_to_toggle.keys():
new_map.append([(time_checkpoint, f"Control + {actual_key}")])
continue
if t == "alt_toggle" and (toggles[t]) and key.startswith("Key"):
actual_key = key[3:]
if actual_key not in map_key_to_toggle.keys():
new_map.append([(time_checkpoint, f"Alt + {actual_key}")])
continue
if t == "windows_toggle" and toggles[t] and key.startswith("Key"):
actual_key = key[3:]
if actual_key not in map_key_to_toggle.keys():
new_map.append([(time_checkpoint, f"Windows + {actual_key}")])
continue
if active_toggle is None:
if key.startswith("Key"):
if typing_mode:
if capital_mode:
current_typed_word.append(key[3:].upper())
else:
current_typed_word.append(key[3:].lower())
else:
typing_mode = True
if capital_mode:
current_typed_word.append(key[3:].upper())
else:
current_typed_word.append(key[3:].lower())
# new_map.append([(time_checkpoint, f"Type {key[3:]}")])
elif key.startswith("Return"):
if typing_mode:
new_map.append([(time_checkpoint, "Type " + "".join(current_typed_word))])
new_map.append([(time_checkpoint, "Enter")])
current_typed_word = []
typing_mode = False
else:
new_map.append([(time_checkpoint, "Enter")])
elif key == "LeftArrow":
new_map.append([(time_checkpoint, "Arrow Move Left")])
elif key == "RightArrow":
new_map.append([(time_checkpoint, "Arrow Move Right")])
elif key == "UpArrow":
new_map.append([(time_checkpoint, "Arrow Move Up")])
elif key == "DownArrow":
new_map.append([(time_checkpoint, "Arrow Move Down")])
elif key == "Backspace":
if typing_mode:
current_typed_word.pop()
new_map.append([(time_checkpoint, "Backspace")])
elif key == "Tab":
if typing_mode:
new_map.append([(time_checkpoint, "Type " + "".join(current_typed_word))])
new_map.append([(time_checkpoint, "Tab")])
current_typed_word = []
typing_mode = False
else:
new_map.append([(time_checkpoint, "Tab")])
elif key == "Space":
if typing_mode:
current_typed_word.append(" ")
else:
new_map.append([(time_checkpoint, "Space")])
elif key == "CapsLock":
capital_mode = not capital_mode
elif key == "Dot":
if typing_mode:
current_typed_word.append(".")
elif key.startswith("Num"):
number = key.split("Num")[-1]
if typing_mode:
current_typed_word.append(number)
else:
typing_mode = True
current_typed_word.append(number)
elif event_base == "KeyRelease":
key = event_key
if key in map_key_to_toggle:
toggles[map_key_to_toggle[key]] = False
active_toggle = None
elif event_base == "MouseMove":
continue # skip this movement
elif event_base == "MouseDownLeft":
new_map.append([(time_checkpoint, "Left Click")])
drag_start = True
if typing_mode:
new_map.append([(time_checkpoint, "Type " + "".join(current_typed_word))])
current_typed_word = []
typing_mode = False
elif event_base == "MouseDownRight":
new_map.append([(time_checkpoint, "Right Click")])
elif event_base == "MouseUpLeft":
if drag_start:
new_map.append([(time_checkpoint, "Drag")])
drag_start = None
# print(new_map[0][0])
# if new_map[0][0][0] > 0.1:
# delta = new_map[0][0][0]
# for i in range(len(new_map)):
# new_map[i][0] = (new_map[i][0][0] - delta, new_map[i][0][1])
# save the new map to a new file
with open("new_map.txt", "w") as file:
for line in new_map:
file.write(str(line))
file.write("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment