0
def kill_my_session():
    while True:
        if keyboard.is_pressed("Esc + ctrl"):
            browser.quit()
            os._exit(0)    
        time.sleep(1)

How to make this if condition works if the Esc+Ctrl keys are pressed together for let's say 3 seconds?

Amr
  • 119
  • 1
  • 10
  • 1
    [https://stackoverflow.com/questions/40649634/determine-length-of-keypress-in-python](https://stackoverflow.com/questions/40649634/determine-length-of-keypress-in-python) – Anytokin May 08 '22 at 15:47

1 Answers1

1
import time
import keyboard

def kill_my_session():
    s = 0
    while True:
        if keyboard.is_pressed("Esc+ctrl"):
            time.sleep(1)
            s+=1
            if s>=3:
                print('Keys are pressed for more than 3 second.')
                s = 0


kill_my_session()

codester_09
  • 5,622
  • 2
  • 5
  • 27