2015-10-10 85 views
2

我是新來的,我希望不要犯任何錯誤!Python 3.5 HookManager SystemError:PyEval_EvalFrameEx

我想使這個簡單的代碼工作,我測試了它在Python 3.4 32位和它的工作,但我需要使用它在Python 3.5.0 64位,但我得到這個錯誤,我不知道怎麼修。

import pythoncom, pyHook 

def OnKeyboardEvent(event): 
    key=chr(event.Ascii) 
    print(key) 

hm = pyHook.HookManager() 
hm.KeyDown = OnKeyboardEvent 
hm.HookKeyboard() 
pythoncom.PumpMessages() 

我得到印在屏幕上按下的鍵,然後我得到這個錯誤:

During handling of the above exception, another exception occurred: 
Traceback (most recent call last): 
File "C:\Python 3.5\lib\site-packages\pyHook\HookManager.py", line 348, in KeyboardSwitch 
event = KeyboardEvent(msg, vk_code, scan_code, ascii, flags, time, hwnd, win_name) 
File "C:\Python 3.5\lib\site-packages\pyHook\HookManager.py", line 208, in __init__ 
HookEvent.__init__(self, msg, time, hwnd, window_name) 
SystemError: PyEval_EvalFrameEx returned a result with an error set 
TypeError: an integer is required (got type NoneType) 

我真的不知道該怎麼辦!

回答

5

你的函數需要返回一個整數值:

def OnKeyboardEvent(event): 
    key=chr(event.Ascii) 
    print(key) 
    return 0 
+1

幫助了我!謝謝! – MANA624

+0

我很高興它做到了! –