Search code examples
pythonpyautogui

pyautogui moveto not working(has correct coords)


import pyautogui
while True:
    test = pyautogui.locateCenterOnScreen('test.png',region=[600,570,680,570],grayscale=False,confidence=.6)
    if test:
        pyautogui.moveTo(1000,1000)
        print(str(test),'found',test.x,test.y)
        break

The print statement is getting run(so its not that the if statement is not getting accessed) Also the move to does work, if run outside of the while statement


Solution

  • With further inspection/test, visual studio code has to be run as admin in order for (moveto) to work while it's not a focused application. This said, if you are using (moveto) and visual studio code has focus, (moveto) will work.

    In conclusion, run VS CODE as admin for (moveto) to work correctly.