K
K
Kryptonit2021-11-22 18:58:09
Python
Kryptonit, 2021-11-22 18:58:09

How to stop code from executing code by successively pressing ctrl + c keys without calling KeyboardInterrupt?

import keyboard
import time
def waiting():
    curtime = time.perf_counter()
    while (time.perf_counter() - curtime) <= 2:
        keyboard.add_hotkey('Ctrl + c', exit())
    cycle()
def cycle():
    while True:
        try:
            keyboard.add_hotkey('Ctrl + c', lambda: print('Hello'))
        except KeyboardInterrupt:
            waiting()
cycle()


It is necessary that the first time you press Ctrl + C, a message is displayed, but the code does not stop,
and if after pressing CTRL + C, CTRL + C is pressed again for 2 seconds, then the code execution
stops, while the program runs indefinitely

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
NN, 2021-11-23
@CERGVARLAXIN

Isn't it easier to type
-until
exit(0)
?)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question