Reputation: 99
My system will goes to sleep if there is no keyboard and mouse action for more than 5 min ( I cannot make any changes in sleep time. For security reason it is set to 5 min).
I am using pyautogui for automation. Pyautogui works in background based on screen resolution by taking keyboard and mouse control. It is taking more than 5 min in my case to complete the execution. After 5 min it going to sleep and keyboard interrupt is generated.
Please let me know is there any solution for these.
Upvotes: 2
Views: 2366
Reputation: 11
One thing I've found to work is running the pyautogui script in a virtual machine, which lets it use the virtual mouse & keyboard. This has the twofold benefit of a. allowing you to do other work while the script is running, and b. the virtual mouse & keyboard are not interrupted with the computer going to sleep.
Hope this helps!
Upvotes: 1
Reputation: 15568
You can just move the mouse all time and deactivate it by taking your mouse to upper left corner:
import pyautogui as p
p.FAILSAFE = True # enables the fail-safe
distance = 200
while True:
p.moveRel(distance, 0, duration=0.5) # move right
distance -= 5
p.moveRel(0, distance, duration=0.5) # move down
p.moveRel(-distance, 0, duration=0.5) # move left
distance -= 5
p.moveRel(0, -distance, duration=0.5) # move up
distance +=10
Upvotes: 1
Reputation: 1129
If you are waiting for some action to be completed, you can simulate a minor mouse movement in a new thread. This will prevent system from sleep.
Upvotes: 0