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!
Your function needs to return an integer value:
def OnKeyboardEvent(event):
key=chr(event.Ascii)
print(key)
return 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With