Put simply, I'm trying to figure out how to run some code when the PyAutoGUI failsafe executes. I've tried searching this problem many times and can't figure out a way to do it.
This is what I want:
The pyautogui.FailSafeException
is raised when the mouse is moved to the upper left corner (x,y of 0, 0). You could catch this exception and run code from there:
import pyautogui import sys
while True:
try:
pyautogui.moveTo() # Any PyAutoGUI (without side effects) call will do here.
except pyautogui.FailSafeException:
print('Running code before exiting.') # Your code here.
sys.exit()