Using xbindkeys to bind the meta key (a.k.a. super key / Windows key) to left click and allow drag and drop

6,579

This is possible. The following will disable the super key and rebind it to the left mouse button. If you wish to preserve the functionality of the super key while also binding to the left mouse button, check out this question.

There seem to be some issues with xbindkeys when we use a modifier key to trigger mouse or keyboard events, so we will first rebind the super key to a non-modifier key using xmodmap.

First, determine the keycode and keysym of your super key using xbindkeys --key, and substitute these values in the commands below. Example output, indicating keycode 134 and keysym Super_R:

m:0x50 + c:134
Mod2+Mod4 + Super_R

Remove the super key from the modifier map:

xmodmap -e 'remove mod4 = Super_R'

Rebind the super key to an unused keysym (in this example, F13):

xmodmap -e 'keycode 134 = F13'

Disable autorepeat for the rebinded key:

xset -r 134

Finally, install xdotool and add the following to ~/.xbindkeysrc to configure xbindkeys (xte or another virtual input program can be used instead of xdotool):

"xdotool mousedown 1"
  F13
"xdotool mouseup 1"
  F13 + release

Now simply kill any existing xbindkeys instance and run xbindkeys. The super key will behave as a left mouse button.

Note that these settings are not preserved across sessions. To set things up automatically, run the following at the start of each session (along with starting xbindkeys):

xmodmap -e 'remove mod4 = Super_R' -e 'keycode 134 = F13' && xset -r 134
Share:
6,579

Related videos on Youtube

Franck Dernoncourt
Author by

Franck Dernoncourt

Updated on September 18, 2022

Comments

  • Franck Dernoncourt
    Franck Dernoncourt almost 2 years

    Is there any way to bind the meta key (a.k.a. super key / Windows key) to a left click using xbindkeys? I would like that hitting the meta key triggers a left click, and hold down the meta key allows to drag and drop (just like it would do when holding down left click).

  • holmb
    holmb over 7 years
    Great answer! Does this answer your question Frank?
  • Dakatine
    Dakatine about 6 years
    Would it be possible to add the mouse binding without removing the original keyboard binding? Thank you!