Simple Mouse Clicker with Python

Subham Khandelwal
2 min readMay 17, 2021

With this tedious time around our life, many of dealt with situation where our computer goes to sleep after some time. We might need to keep it up or be always AVAILABLE in our Communicators.

I have seen people opening notepad and sticking coins to keys to keep the computer signed in. This Simple Mouse Clicker with Python will help you to avoid such situation. All you need is a python installation, copy 5 lines of code and Voila…

The following code works for any Windows machine with support for Python. Lets get started…

If you already have Python and PIP configured in your machine, you can SKIP Steps 1 & 2.

Step 1. Install python on your machine, in-case your organization doesn’t allow installation of software, you can download a zipped version (embedded package) and extract the same at your desired location.

Step 2. Next we have to configure pip for python. “PIP” is famous and widely used package management system to install and manage software packages written in Python. To install PIP, download the get-pip.py file and follow the instructions for configuration.

py get-pip.py

Step 3. Go to the python installation directory and run the following code to get mouse library for Python.

pip install mouse

To check installation you can run

pip list

Step 4. Open a notepad and paste the following lines of codes and save the file with your desired name (e.g. mouse_click.py).

from datetime import datetime
import time
import mouse
if __name__ == “__main__”:
while True:
time.sleep(60)
mouse.click(‘left’)
print(“Left Clicked -> “ + str(datetime.now().strftime(“%d/%m/%Y %H:%M:%S”)))

The code will make left click after every 60 seconds and the output after the click will be displayed in the output console.

Step 5. To make it easier to run, lets create a batch file which will trigger the code on double click. Open a notepad file add the path to your code file with python path. Save the file with .bat extension (e.g. mouse_click.bat)

“C:\Program Files (x86)\Python38–32\python.exe” C:/PycharmProjects/MousePointer/mouse_click.py

The bold is the python.exe path and rest is the path to the code file.

And we are done… Now just double click the batch file and keep the pointer some where on the desktop. The code will trigger every minute simulating the left click, not allowing the computer to go into sleep mode or allowing the communicator to set away status.

Image from the CMD prompt

To exit, just close the command prompt.

--

--