This is a card in Dave's Virtual Box of Cards.

Click the mouse with your keyboard: xbindkeys + xdotool

Page created: 2026-10-20

This is for the X11 windowing system for Unix systems (e.g. Linux and BSD).

Most of the repetitive tasks I do can be scripted in the terminal. But I have a couple unavoidable GUI computer workflows that require at least one mouse click.

I have wanted to do this for so long, but I kept putting it off because it required wiring together two separate tools. But it wasn’t nearly as painful as I’d expected.

Step One: Simulate a click with xdotool

Jordan Sissel’s xdotool is an excellent little utility to simulate pressing keys, clicking mouse buttons, and other windowing tasks.

It’s easy to test with because you can run xdotool right at the command line and get immediate feedback.

Here’s performing a right-click:

$ xdotool click 3

This will right-click for the context menu (I’m running xfce4-terminal at the moment on this computer) and then press the T key to pick the option from the menu to open a new terminal:

$ xdotool click 3 key t

Step Two: Create a keyboard shortcut with XBindKeys

XBindKeys is another excellent little utility. This one is originally by Philippe Brochard.

It normally runs as a daemon and is controlled by a configuration file (~/.xbindkeysrc).

It has three really handy features/commands for testing:

xbindkeys -k      # shows you what key combo you pressed
xbindkeys -n      # runs in the foreground so you can kill it with ctrl+c
xbindkeys_show    # pops up a window with current key bindings

I had good luck running xbindkeys_show as the test command because it shows useful output and you can easily kill it by pressing Escape.

So here’s an example of running it with a configuration to open the xbindkeys_show command when you press the F8 key:

$ cat ~/.xbindkeysrc

"xbindkeys_show"
  F8

$ xbindkeys -n

*** Warning ***
Please verify that there is not another program running
which captures one of the keys captured by xbindkeys.
It seems that there is a conflict, and xbindkeys can't
grab all the keys defined in its configuration file.

(XBindKeys always shows that warning message when running in non-daemon mode. It doesn’t mean something went wrong.)

Now when I press F8, I get a window showing my single key binding.

Step Three: Put them together

Now that both things work, let’s make them work together.

Note that "Release" is not a standard X11 modifier. It is used by XBindKeys to react to key release events rather than key press events. I found that xdotool would perform mouse clicks at the command line just fine, but they wouldn’t work from XBindKeys without this modifier (my thanks to the archlinux wiki for this clue).

Example:

"xdotool click 3 key t"
  F8 + Release

As you can see it’s the same xdotool command as above. This right-clicks and presses the 'T' key when I press the F8 key. (Which, again, happens to open a new terminal in xfce4-terminal).

By performing a mouse click with the keyboard, I made one of my GUI workflows waaaay faster and more pleasant. I wish I’d done this months ago, but better late than never!