Ubuntu – Map Double Click to Key Combination

keyboardmouse

I'm currently using xbindkeys and xdotool to map certain keyboard/mouse combinations to various keyboard shortcuts.

Now, I'm trying to set up my mouse such that double-clicking the middle mouse button presses Ctrl+W (so I can close tabs in Google Chrome by simply double clicking the middle button). Is it possible for xbindkeys to detect double clicks separately from single clicks? If so, how would I do this, and if not, is there an alternative option available?

Best Answer

This question is from 2014, but probably someone still have this problem, so I wanted to share my solution. Before getting to my single line of code, please note, that xbindkeys supports a guile configuration (http://www.nongnu.org/xbindkeys/xbindkeysrc.scm.html) where you can add advanced functionality. I didn't check it out, but probably this will be the best solution for it.

When you want to stick with your old configuration, I wrote a small 'hack' to archive a double action:

"if ls ~/.xbk_double_caps; then [YOUR COMMAND]; else touch ~/.xbk_double_caps; sleep .5; rm ~/.xbindkeys_doubleclick; fi"

    Caps_Lock

This script will activate [YOUR COMMAND] when Caps_Lock key is pressed two times in 0.5 seconds. It checkes if a temporary file exists. If not, it'll touch this file but delete it after 0.5 seconds. Between touching and deleting, [YOUR COMMAND] can be triggered.

It works great for me.

Related Question