我用的是64位的Windows 7。我正在运行pyHook包附带的example.py文件(下面发布的代码)。每当我的活动窗口是Skype时,要么我的计算机崩溃,要么我得到'TypeError: KeyboardSwitch() missing 8个必需的位置参数:..‘。我假设示例中的代码是正确的,如果我没有使用Skype,它运行得很好。有什么想法吗?
from __future__ import print_function
import pyHook
def OnMouseEvent(event):
print('MessageName:',event.MessageName)
print('Message:',event.Message)
print('Time:',event.Time)
print('Window:',event.Window)
print('WindowName:',event.WindowName)
print('Position:',event.Position)
print('Wheel:',event.Wheel)
print('Injected:',event.Injected)
print('---')
# return True to pass the event to other handlers
# return False to stop the event from propagating
return True
def OnKeyboardEvent(event):
print('MessageName:',event.MessageName)
print('Message:',event.Message)
print('Time:',event.Time)
print('Window:',event.Window)
print('WindowName:',event.WindowName)
print('Ascii:', event.Ascii, chr(event.Ascii))
print('Key:', event.Key)
print('KeyID:', event.KeyID)
print('ScanCode:', event.ScanCode)
print('Extended:', event.Extended)
print('Injected:', event.Injected)
print('Alt', event.Alt)
print('Transition', event.Transition)
print('---')
# return True to pass the event to other handlers
# return False to stop the event from propagating
return True
# create the hook mananger
hm = pyHook.HookManager()
# register two callbacks
hm.MouseAllButtonsDown = OnMouseEvent
hm.KeyDown = OnKeyboardEvent
# hook into the mouse and keyboard events
hm.HookMouse()
hm.HookKeyboard()
if __name__ == '__main__':
import pythoncom
pythoncom.PumpMessages()发布于 2015-10-27 17:03:18
当pyHook试图将窗口名称解释为ascii时,我找到了它,并将其跟踪到一个UnicodeDecodeError。在窗口名称中包含unicode字符的Skype上失败。我已经在here上发布了我是如何修复它的。但我不得不重建pyHook。
PS:有点重复的答案,但我想把这个问题和我发现的联系起来。
https://stackoverflow.com/questions/29426211
复制相似问题