pyHook或pythoncom错误?

时间:2015-04-03 04:29:56

标签: python-3.4 skype pyhook

我有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()

1 个答案:

答案 0 :(得分:1)

当pyHook尝试将窗口名称解释为ascii时,我有了这个并将其跟踪到UnicodeDecodeError。它在Skype上失败,其窗口名称中包含unicode字符。我已经发布了如何修复它here。但是我不得不重建pyHook。

PS:有点重复但是想把这个问题与我找到的问题联系起来。