2

私はWindows 7、64ビットを持っています。pyHook パッケージに付属する example.py ファイル (コードは以下に掲載) を実行しています。アクティブなウィンドウが Skype のときはいつでも、コンピューターがクラッシュするか、「TypeError: KeyboardSwitch() missing 8 required positional arguments: ..」が発生します。この例のコードは問題ないと思います。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 に答える