i wrote some code to collect all keys pressed and save them in a .txt
anything i should optimise/change?
import time, keyboard, os
if not os.path.exists("keys.txt"):
with open("keys.txt", "w") as tfile:
pass
def save_keys():
with open("keys.txt", "a") as file:
for i in events:
file.write(i)
while True:
keyboard.start_recording()
time.sleep(5)
events = [str(x)[14:-6] for x in keyboard.stop_recording() if str(x)[-2]=="n"]
save_keys()