Reputation: 47
I know CTRL+C will kill my program, however I have a strict path where my mouse is going and clicking in a while loop, that I do not have time to click on the VS Code Windows , then click terminal, then click CTRL+C, so I was wondering the other best way to do this.
the idea is that I want my pyautogui code in the while loop to happen 300 times.
i=1
while (i<=300)
#do a bunch of stuff
#if the user presses 'esc' the program kills or breaks
Upvotes: 0
Views: 648
Reputation: 661
You can try out this code :
import keyboard # pip install keyboard
i = 1
while (i <= 300):
if keyboard.is_pressed('esc'):
break
print('loop finished')
Upvotes: 0
Reputation: 1180
Pyautogui has a feature that can probably be a good fit for your need. When you put your mouse cursor into one of the corners of the screen, it will trigger a fail-safe and the program will be killed. Read more in the docs.
Upvotes: 2