13 June 2007

Middle-click on a laptop

Lately I've been using my laptop without a mouse (actually on my lap, rather than on a table where there's room for a mouse). My laptop has a touchpad with two buttons. I've enabled Emulate3Buttons in X11 so that I can click both buttons at the same time to simulate a middle-click. This is useful to me, because I use middle-click a lot for pasting (highlighting some text is an implicit 'copy', and a middle-click pastes at the cursor location).

The problem is that I find it difficult to click both buttons at the same time. I usually end up clicking one or the other, which typically throws off the focus and undoes the 'copy' (so the stuff I want to paste is no longer in the X11 clipboard).

(Yes, this is exactly the sort of thing that drives me insane.)

The other day while I was working on a desktop computer, I ran some google searches trying to find a solution, and I found out that if you do shift-numlock and then a 5 on the number pad, that amounts to a middle-click (then you have to do shift-numlock again to resume normal use of the number pad).

(Have you seen the problem with this solution yet?)

I was eager to get home to try this on my laptop, only to feel a crushing humiliation to realize that my laptop does not in fact have a dedicated number pad. (There's a special function key which can convert about a dozen keys on the keyboard into a number pad, but the trick doesn't work on my laptop.)

But then I realized that I could use xmodmap along with the key-handling feature of my window manager. The xmodmap 'pointer' command lets you remap your mouse keys in real time (a left-handed person can use this to make his/her mouse work correctly). If I tell my window manager that control-alt-9 means xmodmap -e 'pointer = 1 3 2' and that control-alt-0 means xmodmap -e 'pointer = 1 2 3', then I can highlight some text (to copy), do control-alt-9, and do a hard-to-screw-up right-click to paste (and then control-alt-0 to resume normal right-click operation).

To do this in fluxbox, just add these two lines to ~/.fluxbox/keys:

Control Mod1 9 :ExecCommand xmodmap -e 'pointer = 1 3 2'
Control Mod1 0 :ExecCommand xmodmap -e 'pointer = 1 2 3'


Anonymous said...

If you just need to paste, shift+insert is the default keypress to paste from the clipboard. It does not simulate a middle mouse click, however.

mbrisby said...

Great tip, thanks.