In this article let's learn how to move the mouse randomly every minute and simulate the mouse movement using the python script.
I will be using the pyautogui Module to automate mouse movement.
Python Script To Move Mouse Randomly Every Minute
Let's import the required modules to move the mouse randomly And simulate the mouse click. import the three Python modules they are pyautogui, random and time as shown below.
import pyautogui as screen
import random
import time
Once we import the required python modules, we get the screen size using screen.size() function call and store the X and Y values.
Use the infinite while loop and generate the random integers from 0 to x-axis and 0 to y axis and store them in two variables X1 and Y1. Use the moveTo() function call to move the mouse to X1 and Y1 random values.
Use the click() function to keep the screen active / avoid screen lock. Pass the x/2 and y-30 variables X and Y axis to the click() function call. If your task is not to keep the screen active you can remove the click() function call
Finally use the time.sleep() To make the python script sleep for 60 seconds after moving the mouse and clicking the x and y axis.
x, y = screen.size()
while True:
x1 = random.randint(0, x)
y1 = random.randint(0, y)
screen.moveTo(x1, y1)
screen.click(int(x/2), y-30)
time.sleep(60)
Python Script
=======================
import pyautogui as screen
import random
import time
x, y = screen.size()
while True:
x1 = random.randint(0, x)
y1 = random.randint(0, y)
screen.moveTo(x1, y1)
screen.click(int(x/2), y-30)
time.sleep(60)
Watch Video For Output
=================================
https://www.youtube.com/watch?v=dW-9rc_q3R4
Conclusion
=======================
The above python script will work for both Windows and Non Windows ( Linux)operating system flavors.
0 Comments