2

我有 Windows 7、64 位。我正在运行 pyHook 包附带的 example.py 文件(下面发布的代码)。每当我的活动窗口是 Skype 时,要么我的计算机崩溃,要么我得到“TypeError:KeyboardSwitch() 缺少 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()
4

1 回答 1

1

我有这个并将其追溯到UnicodeDecodeErrorpyHook 尝试将窗口名称解释为 ascii 时。它在其窗口名称中包含 unicode 字符的 Skype 上失败。我已经在这里发布了我如何修复它。但我不得不重建 pyHook。

PS:有点重复的答案,但想将此问题与我发现的问题联系起来。

于 2015-10-27T09:03:18.487 回答