dpressed = 0
def on_press(key):
if key == (\'d\'):
global dpressed
dpressed+=1
logging.info(\"D: %s\" % dpressed)
Whe
You need to format the key to char format else it won't be equeal to the specific character.
Try
if key.char == ('d'):
Full code being:
dpressed = 0
def on_press(key):
if key.char == ('d'):
global dpressed
dpressed+=1
logging.info("D: %s" % dpressed)
Do you have a listener?
Without a listener the code wont work. Try adding this at the very end of your code.
with Listener(
on_press=on_press,
on_release=on_release) as listener:
listener.join()
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