Checking a specific key with pynput in Python

前端 未结 3 1879
有刺的猬
有刺的猬 2020-12-20 03:49
dpressed = 0

def on_press(key):

    if key == (\'d\'):
        global dpressed
        dpressed+=1
        logging.info(\"D: %s\" % dpressed)

Whe

3条回答
  •  情书的邮戳
    2020-12-20 04:31

    For anyone else that may have this problem, I imported KeyCode from pynput.keybord at the top. Then I changed ('d') to KeyCode.from_char('d'). This should work for anyone with this problem. There is a great explanation here

提交回复
热议问题