Sometimes a PC goes to sleep, launches screensaver or locks the desktop during a long synchronization periods or other GUI inactivity periods, like generation of reports or batch processing. Adding the function below makes the script periodically moving mouse to avoid breaking of the execution. Place the call to the function within your time-consuming loops and custom synchronization functions.
You may simulate mouse moves or clicks anywhere, depending on your needs. If your application has a response on mouse move events, make sure you position mouse cursor on safe areas, like window title or the Taskbar.
cgSleepTimeMax defines a max allowed inactivity period, in seconds. That is, if your screensaver goes on in 10 minutes, you should have cgSleepTimeMax set to 590 seconds or less.
Private Const cgSleepTimeMax = 300 ' 5 minutes Private cgAntiSleep_StopWatch 'Public Function cgAntiSleep() Dim Iter If DateDiff("s", cgAntiSleep_StopWatch, Time()) < cgSleepTimeMax Then Exit Function End If cgAntiSleep_StopWatch = Time() Call LLPlayer.MouseMove(100, 100, 100) For Iter = 100 To 120 Call LLPlayer.MouseMove(Iter, 100, 10) Next End Function