1

Here is my code.

import keyboard
while num <= total_num_list-1:
    show_num = num + 1
    duration_in_min = 1:30
    t = 1
    while t <= duration:
        if keyboard.is_pressed("n"):
            break
        time.sleep(1)
        time_in_min = time.strftime('%M:%S', time.gmtime(t))
        print(f"{time_in_min}/{duration_in_min}")
        t += 1
   num += 1

This code is working for now, but it needs me to hold the "n" key to break the loop because of the delay. What I want is it to have a immediate respond to my key press. What modules can I use or what should I do to make it work?

I am a beginner, sorry if there is any mistakes.

CPPt
  • 11
  • 3
  • Do the answers to this [question](https://stackoverflow.com/questions/5114292/break-interrupt-a-time-sleep-in-python) help at all? – quamrana Aug 01 '22 at 12:47
  • @quamrana not exactly what I wanted, the while loop that I want to break is inside of another while loop. I want it break using a key on the keyboard to continue the rest of the code below. – CPPt Aug 01 '22 at 13:38

0 Answers0