简体   繁体   中英

How to fix pyHook typeError?

I'm making a very simple keylogger, and whenever I type a key, the code works, but it also returns a TypeError: an integer is required (got type NoneType) .

It works fine other then that. I've searched online and have come up blank except pythoncom.PumpMessages() , but pythoncom is being annoying and giving a ModuleNotFoundError: No module named 'pywintypes' . even though I've downloadwed pywin32 (and have tried pypiwin32).

Here is my code:

import pyHook

def keyPress(e):
    if e.Ascii:
        print(chr(e.Ascii))
        if chr(e.Ascii)=="`":
            exit()
keylog = pyHook.HookManager()
keylog.KeyDown = keyPress
keylog.HookKeyboard()

Everything work perfectly except for the TypeError: an integer is required (got type NoneType) that happens whenever I press a key (except when i press the ` key, which exits without an error).

here is the full error message:

TypeError: an integer is required (got type NoneType)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
** IDLE Internal Exception: 
  File "C:\Users\Max\AppData\Local\Programs\Python\Python37\lib\idlelib\run.py", line 147, in main
    handle_tk_events()
  File "C:\Users\Max\AppData\Local\Programs\Python\Python37\lib\idlelib\run.py", line 80, in handle_tk_events
    tcl.eval("update")
SystemError: <built-in method eval of _tkinter.tkapp object at 0x0000024ECF6A9030> returned a result with an error set

[EDIT]:

pythoncom now works (though I can't figure out why), but the code is still throwing the error.

PyHook required me to return an integer in my function, but I did not return anything, hence the error about expecting an integer while getting NoneType. I just needed to add return 0 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM