Skip to content

Instantly share code, notes, and snippets.

@salah3x
Last active October 18, 2021 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save salah3x/fbea506d0d65922b9145533050add737 to your computer and use it in GitHub Desktop.
Save salah3x/fbea506d0d65922b9145533050add737 to your computer and use it in GitHub Desktop.
Prevent monitors from going to sleep by regularly moving the mouse
# Run `pip install mouse` first
from mouse import move, get_position
from time import sleep
# This will move the mouse in squares.
# You can change the size of the square (default 200px) and the
# movement duration (default 2s), the programm will sleep for 20s.
# You can change the square implementation or introduce some randomness
# to the above values to make it difficult to be detected.
while True:
move(get_position()[0] + 200, get_position()[1], duration=2)
sleep(20)
move(get_position()[0], get_position()[1] + 200, duration=2)
sleep(20)
move(get_position()[0] - 200, get_position()[1], duration=2)
sleep(20)
move(get_position()[0], get_position()[1] - 200, duration=2)
sleep(20)
@salah3x
Copy link
Author

salah3x commented Oct 18, 2021

Another implementation using the autopy library:

from autopy.mouse import smooth_move, location
from time import sleep

while True:
	smooth_move(location()[0] + 200, location()[1], duration=2)
	sleep(20)
	smooth_move(location()[0], location()[1] + 200, duration=2)
	sleep(20)
	smooth_move(location()[0] - 200, location()[1], duration=2)
	sleep(20)
	smooth_move(location()[0], location()[1] - 200, duration=2)
	sleep(20)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment