Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3.5 HookManager SystemError: PyEval_EvalFrameEx

Tags:

python

I'm new here and I hope not to do any mistakes!

I'm trying to make this simple code work, I tested it on Python 3.4 32 bit and it worked but I need to use it on Python 3.5.0 64 bit but I get this error that I don't know how to fix.

import pythoncom, pyHook

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

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

I get the pressed key printed on the screen and then I get this error:

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)

I don't really know what to do!

like image 706
Stefano Borzoni Avatar asked Oct 10 '15 17:10

Stefano Borzoni


1 Answers

Your function needs to return an integer value:

def OnKeyboardEvent(event):
    key=chr(event.Ascii)
    print(key)
    return 0
like image 200
Mario Flores Avatar answered Sep 22 '22 19:09

Mario Flores