Keyboard shortcut to simulate a mouse right-click in CrunchBang Linux

I don’t have Linux installed on my Windows 8 Asus laptop, so when I want to do some Linux work I usually just boot into a live session from a USB key. My favourite Linux distribution is CrunchBang because it’s really lightweight and Debian-based so I can easily apt-get whatever applications I might need during a live session. There’s just one problem: the right click doesn’t work on my laptop’s touchpad.

If CrunchBang was actually installed on the hard disk of the laptop, I could presumably work out how to configure the mouse properly. However, since I run CrunchBang as a live session, I would need to reconfigure it every time I boot. Whenever I need to right-click, I therefore use the following workaround:

  • I position the mouse where I want to right-click.
  • I type "Alt+F2" on the keyboard to open the “Run program” dialog box.
  • I then run the following command: "xdotool click 3".
Run program dialog used to run xdotool to simulate right click

To simulate a right click in CrunchBang, position the mouse pointer, then press Alt+F2 to open the “Run Program” dialog box, type “xdotool click 3” and press return.

xdotool simulates mouse and keyboard events in X Windows. Here, I’m using it to simulate a right click wherever the mouse is currently positioned. This works fine for an occasional right click, but if I’m doing something that involves a lot of right-clicking, it’s obviously inconvenient.

To create a keyboard shortcut to simulate a right click, I use the following method.

First, I add the following as line 315 of the Openbox configuration file in my home directory ("~/.config/openbox/rc.xml"):

<keybind key="W-r"><action name="Execute"><command>xdotool click 3</command></action></keybind>

If desired, the config file can be modified automatically using sed to add the new key binding at line 315. This is the command to use:

sed -i '315i<keybind key="W-r"><action name="Execute"><command>xdotool click 3</command></action></keybind>' ~/.config/openbox/rc.xml

A sed command running in a console to edit the Openbox config file

Here’s how the file "rc.xml" looks in geany once it has been modified:

Modified Openbox congif file

To put that into effect, I restart Openbox. This can be done by running the following command in a console:

killall -USR1 openbox

Alternatively, open the Openbox main menu by pressing the "Super+Space" shortcut, then select "Settings->Openbox->Restart", as shown below.

Openbox main menu - restart Openbox

To restart Openbox, press Super+Space to access the main menu, then select “Settings->Openbox->Restart”.

Note that the "Super" key is the the one with the Windows symbol. On my keyboard, it’s immediately to the left of the Alt key near the lower left corner of the keyboard.

I can then right click by pressing "Super+r". For some reason, it doesn’t work on the desktop itself, but it works perfectly in application windows.

TLDR (short version):

To do the whole thing quickly, just run the following commands in a console:

sed -i '315i<keybind key="W-r"><action name="Execute"><command>xdotool click 3</command></action></keybind>' ~/.config/openbox/rc.xml
killall -USR1 openbox
This entry was posted in Uncategorized and tagged , , , , , , , , , , , . Bookmark the permalink.

One Response to Keyboard shortcut to simulate a mouse right-click in CrunchBang Linux

  1. brilliant solution! ive the same problem and your solution works, thanks man😀

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s