I have a need to repeatedly click in an application’s window many times for testing purposes at work. Since I have no intention of doing that manually and developing RSI, I set up i3 to automate this for me.

You may find this useful too - for gaming, for instance.

Setup:

  • Install xdotool

  • Create a Bash script called start_stop_autoclick.shsomewhere (I have a ~/scripts directory in my home directory for that purpose):

    #!/bin/bash
    
    DELAY=$1
    BUTTON=$2
    CMD=xdotool
    ARGS="click --delay $DELAY --repeat 99999999999999999 $BUTTON"
    
    PID=$(ps -C $CMD -o pid,cmd | awk "/$ARGS/ {print \$1}")
    if [ "$PID" ]; then
      kill $PID
    else
      $CMD $ARGS
    fi
    
  • Edit ~/.config/i3/config and add the following lines:

    # Start / stop autoclick
    
    bindsym $mod+Ctrl+button1 --whole-window exec --no-startup-id /bin/bash ~/scripts/start_stop_autoclick.sh 250 1
    bindsym $mod+Ctrl+button2 --whole-window exec --no-startup-id  bin/bash ~/scripts/start_stop_autoclick.sh 250 2
    bindsym $mod+Ctrl+button3 --whole-window exec --no-startup-id /bin/bash ~/scripts/start_stop_autoclick.sh 250 3
    

How to use it:

Hover over the button or element you want to click on repeatedly then press Ctrl+Meta and click with the button you want to autorepeat.

Be careful not to move the mouse otherwise it’ll start autoclicking where you don’t want and possibly wreak havoc in your windows.

To stop it, simply hit Ctrl+Meta until it stops.

How to modify it to suit your needs:

The three lines above in ~/.config/i3/config enable autoclicking on the left, right and middle buttons. If you only want it on one button, ditch the lines you don’t need.

By default, they autoclick with a delay of 250 ms between clicks (i.e. 4 times per second). If you need it to click slower or faster, change the value of 250 to the delay you need.

And of course, change the key modifiers to whatever you want if Ctrl+Meta doesn’t work for you.