Mouse mover in python

Views: 9
0 0
Read Time:1 Minute, 17 Second

Hi All, I recently came across one really really boring issue that is how to keep the monitor always turned on while away avoiding the stand-by and consequently close the VPN connection. I’m probably the laziest person of the entire planet (or galaxy) and for avoiding to go and search on google or in the system settings, I just implemented my programmatic way of keeping the mouse moving randomly, so that I can avoid to afford the enormous task of clicking on the “Connect to VPN” button. I found then this beautiful library that can help me control the mouse using python with just few lines of code. Holy grail for my laziness!!

I found this library pyautogui (https://pyautogui.readthedocs.io/en/latest/)

PyAutoGUI lets your Python scripts control the mouse and keyboard to automate interactions with other applications. The API is designed to be simple. PyAutoGUI works on Windows, macOS, and Linux, and runs on Python 2 and 3.

And it does what is said! I created this script that I keep running while on lunch break, so my computer will not go in stand-by, my VPN will not quit and all my terminal sessions will still be opened!!

Ejoy

import pyautogui
import time

from random import randint, seed

seed(3)

# get the screen resolution
x, y = pyautogui.size()

while True:
	pyautogui.moveTo(randint(0, y), randint(0, x), duration = 1)
	time.sleep(1)

Hope this will solve your exact same problem! If not would be interesting hearing from you what actually solved.

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %
Previous post How to generate random numbers with python
Next post How to setup Phalcon framework in a Docker container
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x