【问题标题】:How to fix pyHook typeError?如何修复pyHook typeError?
【发布时间】:2019-09-18 14:01:11
【问题描述】:

我正在制作一个非常简单的键盘记录器,每当我键入一个键时,代码都会起作用,但它也会返回一个TypeError: an integer is required (got type NoneType)

除此之外它工作正常。我在网上搜索过,除了pythoncom.PumpMessages() 之外都是空白的,但是pythoncom 很烦人并给出了ModuleNotFoundError: No module named 'pywintypes'。即使我已经下载了 pywin32(并尝试过 pypiwin32)。

这是我的代码:

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()

除了TypeError: an integer is required (got type NoneType) 之外,其他一切都运行良好

这里是完整的错误信息:

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

[编辑]:

pythoncom 现在可以工作了(虽然我不知道为什么),但是代码仍然抛出错误。

【问题讨论】:

    标签: python keylogger pyhook


    【解决方案1】:

    PyHook 要求我在我的函数中返回一个整数,但我没有返回任何内容,因此在获取 NoneType 时需要一个整数的错误。我只需要添加return 0

    【讨论】:

      猜你喜欢
      • 2019-10-23
      • 2016-05-23
      • 2019-11-15
      • 1970-01-01
      • 1970-01-01
      • 2023-01-27
      • 2015-03-16
      • 1970-01-01
      相关资源
      最近更新 更多