'pyautogui code only working when debugging (with a breakpoint), and even then not completely
I want to make a program that automatically cleans my pc with CCleaner, by searching for specific images on the screen, moving the mouse to that position, and clicking on it, and waiting 0,5 secs if it doesn't find the image. the first loop, which opens CCleaner works as intended, but what it seems like it skips the second loop, and then tries doing the one after that. When I try to put a breakpoint at the second try, it appears that it successfully moves the mouse to where it needs to go, but it doesn't click() it, and then break and tries to do the next loop. sleep() after every line, but it didn't fix it so it shouldn't be timing issue.
Why does it only move the mouse where it needs to go, when I'm debugging, and why isn't it click()ing?
import pyautogui
import time
import PIL
import picsData
pics = picsData.__dict__.get("pics")
while True:
try:
point = pyautogui.center(pyautogui.locateOnScreen(pics.get("ccleaner")))
pyautogui.moveTo(point)
pyautogui.click(clicks=2)
break
except:
time.sleep(0.5)
time.sleep(0.5)
while True:
try:
point = pyautogui.center(pyautogui.locateOnScreen(pics.get("health")))
pyautogui.moveTo(point)
pyautogui.click(clicks=2)
break
except:
time.sleep(0.5)
while True:
try:
point = pyautogui.center(pyautogui.locateOnScreen(pics.get("healthstart")))
pyautogui.moveTo(point)
pyautogui.click()
break
except:
time.sleep(0.5)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
