Looking for an autoclicker

13 réponses [Dernière contribution]
Beko
Hors ligne
A rejoint: 08/31/2019

Like the title says I'm looking for an autoclicker for Trisquel, in my research I found xdotool among others, but I need for it to have a variable time between clicks.

So for example: between 1-2 sec

Click
Stop(1.2sec)
Click
Stop(1.9sec)
Click
Stop(1.5sec)
...

is there any program that anyone can tell me about? I read the xdotool man page through and either wasn't able to find it or I can't do it with xdotool.

Thanks!

chaosmonk

I am a member!

I am a translator!

Hors ligne
A rejoint: 07/07/2017

You could try something like this:

```
#!/bin/bash
MIN=1 # minimum wait time in seconds between clicks
MAX=2 # maximum wait time in seconds between clicks
STEP=.001 # controls number of digits after the decimal point
while [ 1 ]; do # loop forver until you exit with Ctrl+C
xdotool click 1 # click left mouse button
WAIT=$(seq $MIN $STEP $MAX | shuf | head -n1) # generate random wait time
sleep $WAIT # wait
done

```

Beko
Hors ligne
A rejoint: 08/31/2019

Thank you, this will save me from a lot of repetitive strain injury :)

I saved it as Autoclicker.script then made it executable. It works perfectly

zigote
Hors ligne
A rejoint: 03/04/2019

Replace

while [1]

with

while true

and
sleep $WAIT

with

sleep "${WAIT}"

https://www.shellcheck.net/wiki/SC2086
https://www.shellcheck.net/wiki/SC2161

Magic Banana

I am a member!

I am a translator!

Hors ligne
A rejoint: 07/24/2010

WAIT is always a number in chaosmonk's script: the quotes are useless (and so are the curly brackets). I prefer "while true" to "while [ 1 ]" but that is merely a stylistic point.

More interestingly, $RANDOM (which is Bash specific) would make the script simpler:

#!/bin/bash
MIN=1
MAX=2
while true
do
xdotool click 1
sleep $(echo "$MIN + ($MAX - $MIN) * $RANDOM / 32767" | bc -l)
done

For a script that is portable across shells, one can read /dev/urandom with 'od':

#!/bin/sh
MIN=1
MAX=2
while true
do
xdotool click 1
sleep $(echo "$MIN + ($MAX - $MIN) * $(od -A n -N 2 -d /dev/urandom) / 65535" | bc -l)
done

zigote
Hors ligne
A rejoint: 03/04/2019

> WAIT is always a number in chaosmonk's script: the quotes are useless (and so are the curly brackets)

Due to the way it is generated and considering that bash does not understand floating point numbers - it is always a string.

> I prefer "while true" to "while [ 1 ]" but that is merely a stylistic point.

Yes, and ambiguity is a bad style: "while [ 0 ]" also creates an infinite loop. If you want to work with numbers instead for an infinite loop you would better use "while (( 1 ))". However "true" is shorter and more readable, that's why it is the commonly accepted way for infinite loops.

The simplest way to generate a random float between 1 and 2 without any fancy gymnastics is:

WAIT=1.$(( RANDOM % 9 ))

Explanation: "$(( RANDOM % 9 ))" is a random int between 0 and 9

Then the whole script is simplified to:

#!/bin/bash
while true; do
sleep "1.$(( RANDOM % 9 ))"
xdotool click 1
done

Magic Banana

I am a member!

I am a translator!

Hors ligne
A rejoint: 07/24/2010

Due to the way it is generated and considering that bash does not understand floating point numbers - it is always a string.

Sure. What I meant is $WAIT only contains digits and the dot; no special character the shell would interpret and that would justify the need for quotes.

"$(( RANDOM % 9 ))" is a random int between 0 and 9

No, it is not. It is an integer between 0 and 8. $(( RANDOM % 10 )) would generate an integer between 0 and 9. And, even with that change, it is not enough to reach 2 seconds. And that is not flexible: for instance, it cannot be adapted to have a random delay between 1 and 3 seconds. And the .1s granularity may be too coarse, depending on the application.

zigote
Hors ligne
A rejoint: 03/04/2019

Yes, you are right about "% 10" (it was late at night when I typed it).

The requirement was "between 1 and 2 seconds" without any specific flexibility. Now I also read it is about a "mindless videogame", so it still doesn't seem necessary.

If flexibility and higher precision is required:

sleep "$(( MIN + RANDOM % (MAX-MIN) )).$(( RANDOM % 1000 ))"

This will sleep randomly from MIN to MAX-0.001 seconds.

Magic Banana

I am a member!

I am a translator!

Hors ligne
A rejoint: 07/24/2010

I personally consider that solution more obscure than using 'bc -l' to do floating-point math. But that is a question of opinion I guess. Also, it only works if both MIN and MAX are integers. And the distribution is not really uniform because $RANDOM is between 0 and 32767. For the decimals: there is a probability 33/(33+32) to get a number between 0 and 767, and only 32/(33+32) to get a number between 768 and 999. For the considered use, the difference does not matter at all though.

Beko
Hors ligne
A rejoint: 08/31/2019

While I have so many people responding to this post would anyone happen to know how I could assign this script to a hotkey in which I would press the hotkey to start and stop instead of Ctrl+C-ing the terminal window.

chaosmonk

I am a member!

I am a translator!

Hors ligne
A rejoint: 07/07/2017

In `Autoclicker.script`, change `#!/bin/bash` to `#!/bin/bash /path/to/Autoclicker.script`. (Replace "/path/to" with the location of the script.) This will allow you to kill the script with

$ killall Autoclicker.script

Assuming you use MATE, go to Control Center -> Keyboard Shortcuts and map "/path/to/Autoclicker.script" to one keyboard shortcut and "killall Autoclicker.script" to another.

chaosmonk

I am a member!

I am a translator!

Hors ligne
A rejoint: 07/07/2017

What's this for, out of curiosity?

Beko
Hors ligne
A rejoint: 08/31/2019

A mindless videogame haha. Requires me to click repeatedly but detects autoclickers so I needed the random time between clicks to throw off that detection.

Beko
Hors ligne
A rejoint: 08/31/2019

Took me a while because I didn't have the time to fiddle around in settings earlier but I was able to set the tilde key and ctrl as my hotkeys.

Thanks!