5

Is there a way I can use xdotool to perform a certain number of mouse clicks per second while holding down a certain key?

1
  • 2
    You want xdotool to click and hold the key down or you want xdotool to click when you hold the key down?
    – Seth
    May 6, 2014 at 19:35

2 Answers 2

3

This is my bash script for xdotool. You can set it with a keyboard shortcut. It stops when you move the mouse. Of course you can make your own script to fit your tastes.

#!/bin/bash
eval $(xdotool getmouselocation --shell)
echo $X $Y
x1=$X
y1=$Y
COUNTER=1
COUNTEND=100000
#REPEAT= 0.09s
while [ $COUNTER -lt $COUNTEND ]; do
  echo the counter is $COUNTER
  xdotool click 1
  eval $(xdotool getmouselocation --shell)
  # cancel if mouse moved
  if [ $x1 != $X ] || [ $y1 != $Y ]; then
    echo Mouse moved - script terminated
    exit 1
  fi
  #this sleep works for repetition rate
  sleep 0.01s
  let COUNTER=COUNTER+1
#  xdotool click --delay 90 --repeat 1000 1
done
3
  • Not bad! I expect forking and executing 4 new processes every 10 ms would take up a considerable amount of resources and lock up the kernel in critical sections quite a bit. Can you maybe port the script to something like Python, Perl or C that uses libxdo or a similar library directly without the need to spawn new processes so frequently? Jan 12, 2018 at 15:38
  • Also add a xdotool keydown [key] above the while loop and xdotool keyup [key] in the if statement to hold down the key
    – Evan Chen
    Jan 12, 2018 at 17:13
  • hmm i have my own python app that uses xdotool but im not using libxdo.. Its quite easy to add more features to the mouse clicker but im quite busy lately so ill do it some time in the future.. github.com/FDJ-Dash/Multitool/blob/master/mouseclicker/… Aug 13, 2018 at 16:47
0

Partial answer. First, you have to bind your key to run code. The easiest way IMHO to do that is with AutoKey which provides that feature along with a whole lot of other keyboard automation features.

Once that's taken care of, then you just write a very small keyboard macro (in Python) which uses xdotool to issue the mouse event and then sleep for one second divided by the number of events you want per second. The part I'm not sure about is detecting the key release to stop the process, but since the macro is written in Python, almost anything should be possible.

Because the code takes time to run, etc., this will not be precisely so many per second and you'll have to adjust the sleep time accordingly. The clicks will not be perfectly equally spaced for the same reasons as well as things like system load.

For most practical applications, an approach like this should be "good enough".

If this sounds like it would work for you, then we could get deeper into the actual implementation on or off forum.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .