So I have an auto clicker script that is this simple command: Tribute

xdotool click --delay 5 --repeat 900000 1

I have to switch to the terminal and Ctrl-C interrupt the script to stop it. Then just run it again to restart.

So I started to use the read command to check for key input to avoid this switching back and forth. However that only checks for input at the terminal. I am clicking somewhere else, and want to be able to start and stop from there.

Is there a version of read that can check for keystrokes globally?

  • 2
    I'm not sure about something that's coded directly in the script itself, but another option is to use another keystroke to trigger a separate script that kills the first script. I'm using KDE Plasma, which allows you to easily assign a script to arbitrary keystrokes from the GUI system settings. – Sparhawk May 23 '17 at 4:49
  • That seems a bit hackish. I could see going that route, but hopefully there is a better way. – Jason Basanese May 23 '17 at 15:32
  • I feel like most things involving xdotool are hackish to begin with. – Sparhawk May 23 '17 at 22:14
  • 1
    @Sparhawk Good point. – Jason Basanese May 24 '17 at 2:31

Bit late here, but here is a solution. By typing xinput --list, you get a list of all the input devices in your system. The trick is with xinput --query-state. If you go into terminal and you list the inputs, you can then do xinput --query-state [YourKeyboard].

1 class :

Now, you will need to hold down the key, so you can either

  • Use > to write to a file, letting you hold down the key when you execute the command
  • Make a quick bash script

    while true; do

    xinput --query-state [YourKeyboard] | grep 'down'


    # StackExchange does not like bash

EDIT: I am not on Linux right now, so I cannot try this, but I heard you can use xinput --test as well

Once you find the correct key, make a script like this.

while true; do

inp=`xinput --query-state <KEYBOARD#ID> | grep -o 'button\[<KEYBOARD#BUTTON>\]=down'`

if [ ! -z "$inp" ]; then

xdotool click 1



This will spam click the mouse button while the user holds down a button

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.