简单地说,我试图找出执行PyAutoGUI故障保险时如何运行一些代码。我已经尝试搜索此问题很多次了,但找不到解决方法。
这就是我想要的:
答案 0 :(得分:1)
将鼠标移到左上角(x,y of 0,0)时,将引发pyautogui.FailSafeException
。您可以捕获此异常并从那里运行代码:
导入pyautogui 导入系统
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()