我想创建一个按键记录器,它会监听按键“w”“a”“s”“d”,每当检测到这些按键时,就会将它们添加到列表中。到目前为止我有这段代码
from pynput.keyboard import *
keys_pressed=[]
def on_press(key):
print(key)
def on_release(key):
if key==Key.esc:
return False
with Listener(on_press=on_press,on_release=on_release) as listener:
listener.join()
如何检查特定键是否被按下,并将其添加到keys_pressed列表中?
精慕HU
相关分类