当我在一个简单的while循环中使用Try / except键盘中断时,除了工作正常,但当使用它仍然非常简单,但更多涉及它现在将不再拾取键盘中断所以我没有办法如果我愿意,手动打破循环。
问题:让keyinterrupt在下面使用我的脚本的最佳方法是什么?
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!")`