I have a pyautogui program that clicks a specfic button when it appears in another software I have, the problem is that whenever I have the program running it doesn't move the mouse toards it with pyautogui.MoveTo() since the python program window is not active it should be active in order to move the mouse, this creates another issue, which is that whenever I will click the other program button it will be inactive again and the current active window will be the one of the software.
Note : by active I mean focused
import pyautogui
import time
pyautogui.FAILSAFE=False
if __name__ == "__main__":
while True:
pyautogui.moveTo(10, 10)
found = False
try:
button_location = pyautogui.locateOnScreen('confirm_button.png', confidence=0.8)
if button_location is not None:
button_center = pyautogui.center(button_location)
x, y = int(button_center.x), int(button_center.y)
pyautogui.moveTo(x, y)
pyautogui.click()
found = True
except pyautogui.ImageNotFoundException:
pass
if found:
print("Clicked 'Continue' button.")
found = False
time.sleep(10)
I managed to fix the problem after some hours. Apparently, the software I was trying to automate had Admin privileges, in order to make the program able to access it using pyautogui, you will need to run the Python program as administrator as well.