【发布时间】: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 现在可以工作了(虽然我不知道为什么),但是代码仍然抛出错误。
【问题讨论】: