When I use Try/except with keyboard interrupt in a simple while loop the except works fine, but when using it with something still pretty simple, but more involved it will now no longer pickup the keyboard interrupt so I dont have a way to break the loop manually if I want to.
QUESTION: What is the best way to get keyboardinterrupt to work with my script below?
CODE:
try:
count = 0
xyz = 0
while pyautogui.locateOnScreen('add.png', region=(288, 147, 560, 1016), grayscale=True)!=None:
while pyautogui.locateOnScreen('add.png', region=(288, 147, 560, 1016), grayscale=True)!=None:
count=count+1
print (count)
x, y = pyautogui.locateCenterOnScreen('add.png', region=(288, 147, 560, 1016), grayscale=True)
pyautogui.click(x, y)
w = 0
while w < 17:
pyautogui.click(945, 1166)
w=w+1
xyz=xyz + 1
time.sleep(1)
except KeyboardInterrupt:
print ("KeyboardInterrupt detected!")`