我的代码是:
import keyboard
pressed = ""
def on_key_press():
print("Key pressed.")
global pressed
# Took me 1 hour to figure out this.
if charset.chars.__contains__(keyboard.read_key()):
print("processing slangs...")
print("*process*")
else:
print("registered key.")
pressed += keyboard.read_key()
print(pressed)
keyboard.on_press(on_key_press())
keyboard.wait()
我以root身份运行它。当我按下一个键时,它会按预期打印该键。但是,当我在它之后按下任何键时,它只会返回一个错误,如下所示:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/dist-packages/keyboard/_generic.py", line 22, in invoke_handlers
if handler(event):
File "/usr/local/lib/python3.9/dist-packages/keyboard/__init__.py", line 474, in <lambda>
return hook(lambda e: e.event_type == KEY_UP or callback(e), suppress=suppress)
TypeError: 'NoneType' object is not callable
它会不断打印出这样的错误,不管我按什么键。请帮忙。