1. Introduction

The ability to set up auto-clicking for the mouse enables automation for various graphical tasks and processes. Whether it’s navigating through menus, filling out forms, or conducting repetitive testing, auto-click provides a means to streamline interactions with the computer.

In this tutorial, we’ll learn how to set up the mouse to auto-click at specified intervals.

2. Using xdotool

xdotool enables the simulation of mouse activity and keyboard input, in addition to resizing and moving windows. Here, we’ll only focus on configuring auto-clicks for the mouse.

2.1. Installation

In case it’s not already available, we can install xdotool via the local package manager:

$ sudo apt install xdotool

This command installs the xdotool. So, let’s verify our installation by running the command:

$ xdotool -v
xdotool version 3.20160805.1

Option -v is the shorthand for –version and shows the version of the xdotool currently installed on our system.

2.2. Basic Clicks

We can use the xdotool click command to send a click using a given mouse button:

$ xdotool click --repeat 10 --delay 2000 1

The above command sets 10 auto-clicks for the left mouse button with a delay of 2000 milliseconds (two seconds).

In this case, xdotool click construct sends automated clicks with specified parameters.

  • –repeat 10 sets the total number of clicks to 10
  • –delay 2000 sets the delay between two consecutive clicks to 2000 milliseconds, i.e., two seconds
  • 1 specifies the button to click as the left mouse button

In fact, xdotool provides a total of five options for sending the clicks with different buttons:

  • 1: left
  • 2: middle
  • 3: right
  • 4: wheel up
  • 5: wheel down

Because of their special function, let’s look at the wheel buttons separately.

2.3. Wheel Clicking

Wheel up and wheel down buttons scroll the currently active screen in the direction set for the wheel up and down buttons of the mouse, respectively.

Let’s test setting auto-clicks for the wheel-up button:

$ xdotool click --repeat 5 --delay 1000 4

The command sets 5 auto-clicks for the wheel up button with a delay of 1000 milliseconds between each two, i.e., a one-second pause. As we execute this command, the screen of an active window starts moving in the direction of the wheel-up button for the mouse.

Conversely, using the above command without the –repeat option will click only once with the specified mouse button and exit.

Altogether, xdotool is a versatile tool that offers several options for performing automatic mouse clicking.

3. Using xAutoClick

The xAutoClick is an auto-clicker application that lets us click the left mouse button automatically.

3.1. Installation

We can download the source package from the SourceForge project page using wget:

$ wget http://sourceforge.net/projects/xautoclick/files/xautoclick/xautoclick-0.31/xautoclick-0.31.tar.gz

Next, we process the downloaded archive:

$ tar -xvzf xautoclick-0.31.tar.gz

The tar command extracts the contents of our downloaded source package in the current directory. Now, let’s compile it from the source:

$ cd xautoclick-0.31/
$ ./configure && make && sudo make install

The above commands change the directory to xautoclick-0.31, configure, and compile the source code. Finally, the make install command installs the compiled software onto our system with sudo privileges.

Depending on the system, these commands install one or more executable binaries including the command line version of the xAutoClick tool, cautoclick.

3.2. Usage

Now, let’s use the command line version, cautoclick, to set left auto-click for the mouse:

$ cautoclick -i 20000 -n 10

In short, this command automates mouse clicks with a 20-second interval between clicks for a total of 10 clicks. In particular, the -i 20000 parameter sets the time interval between two mouse clicks to 20000 milliseconds (20 seconds). The -n option is used to specify the number of mouse clicks, in this case 10.

Additionally, we can set the time delay before the application starts mouse clicks with the -p option.

4. Using Python

We can also set the auto-click for the mouse using Python.

Let’s install the library of our choice with pip:

$ pip install pyautogui

Once the pyautogui library is installed successfully, we can use it in a Python script to automate mouse clicks:

import time
import pyautogui

for j in range(10):

Here, the import command includes the libraries in a script, in our case time and pyautogui. Then, the for loop is used for the repetitive task of clicking the mouse. pyautogui.click() emulates the left mouse clicks. Finally, the time.sleep() function is used to take a pause, in this case for 2 seconds.

Let’s save the above script in a file named mouse_clicker.py and run it:

$ python mouse_clicker.py

This Python script sets 10 auto-clicks for the left mouse button with a time interval of 2 seconds. Similarly, we can use the rightClick() function from the pyautogui library to emulate the right-click for the mouse.

Lastly, we can scroll up and down with the scroll() function. The scroll() function accepts an integer argument, where a positive value represents scrolling up and a negative value means scrolling down.

5. Conclusion

In this article, we learned different ways to emulate auto-clicking with the mouse at predefined intervals.

First, we discussed how to install the xdotool followed by its usage to set the auto-clicks for the mouse emulating left button clicks. Additionally, we learned how to set up auto-clicking for the wheel-up mouse button with the xdotool. Next, we downloaded, compiled, and installed the xAutoClick tool from the source code. Then, we used the command line version of xAutoClick, cautoclick, to perform automatic left mouse clicks. Finally, we achieved the same goal of setting the auto-clicks for the left mouse button using Python.

We can select any method depending on our preferences and needs.

Comments are closed on this article!