4

I have a game that requires me to click a moving object repeatedly, which is extremely difficult if you only have a touchpad with no separate mouse buttons.

What I want is to have a tool/script that repeatedly emulates a mouse click (left button, maybe around 5 clicks per second) while a specific keyboard button or combination is held down, e.g. Control (right)+Menu.

I know I can emulate repeated clicks with a command like

xdotool click --repeat 10 --delay 200 1

but I have no idea how to make it click while a specific keyboard combination is held down instead of a fixed number of clicks.

1
  • @JacobVlijm Yes, but I would like to just hold down the key to keep it clicking, not to wear out my keyboard...
    – Byte Commander
    Feb 5, 2017 at 11:54

3 Answers 3

1

Here's my first and fifth attempts. The first is decent if you don't need to change the delay. It seems to have some problems with certain key combinations, not sure what was causing it however.

Method 1, in ~/.xbindkeysrc:

keystate_scrolllock = enable

"xdotool click 1"
    Scroll_Lock

Method 5:

keystate_scrolllock = enable

"/home/USER/infinite_clicks.sh event16 KEY_SCROLLLOCK 0.1 &"
    Scroll_Lock

With infinite_clicks.sh being:

#!/bin/bash
kbd=$1 #"event16"
key=$2 #"KEY_SCROLLLOCK"
delay=$3 #"0.1"
fn=`basename "$0"`

if [  $# -le 1 ]; then 
    echo "Usage: $fn input_device key_name delay"
    echo "Example: $fn event16 KEY_SCROLLLOCK 0.1"
    echo "Must run as superuser."
    exit 1
fi 

# do not start if already started
if [[ $(pidof -o %PPID -x $fn) ]]; then
    exit 0
fi

while true; do
    # this is why you need to use sudo/superuser
    evtest --query  /dev/input/$kbd EV_KEY $key

    # get evtest return code, if it's 0 the key is up
    if [[ "$?" -eq "0" ]]; then
      break
    fi

    xdotool click 1 &
    sleep "$delay"
done

exit 0

With this code you also need to run xbindkeys as sudo xbindkeys -f ~/.xbindkeysrc

You can find your keyboard event number using sudo evtest then find the key names using sudo evtest /dev/input/eventXXX using the event number.

2
  • Wow, thanks. I tested only method 1 so far and it works well, but you should add that the line keystate_scrolllock= enable is also required in the .xbindkeysrc file to work. Will test method 2 soon as well.
    – Byte Commander
    Nov 1, 2017 at 22:12
  • @ByteCommander Strange, I didn't need to set that. Though maybe it's set somewhere else. Added to answer since it probably can't do any harm. I only used ScrollLock because it's a key I never use.
    – AnnanFay
    Nov 1, 2017 at 22:17
0

I've been using ClickItAuto,a little program which, as any Java software, can be executed in multiple OS

https://github.com/DaGammla/ClickItAuto

0

There are various auto clicker software available online to download.

I recommend for you Max Auto Clicker because is a cross platform application (Linux + Windows), free and safe to use.

You must log in to answer this question.

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