我需要清理键盘记录程序的响应。我需要输入一个简单的键,然后在表中输入日期。我正在使用Spyder。我的当前响应的外观示例如下:“'c'2020-11-02 21:18:49.426134's'2020-11-02 21:18:49.426134”。下面是
`from pynput import keyboard
from datetime import datetime
import os
time = str(datetime.now())
addornew=''
if os.path.isfile('Keylog.txt'):
addornew = 'a'
else:
addornew = 'w'
f = open('Keylog.txt',addornew)
def on_press(key):
f.write(str(key)+time)
def on_release(key):
if key == keyboard.Key.esc:
# Stop listener
f.close()
return False
listener = keyboard.Listener(
on_press=on_press,
on_release=on_release)
listener.start()
`