[NB: obviously and purposely, this does not "swap" a keyboard key with a mouse button; it just lets a keyboard key act like a mouse button; but the mouse button will NOT start acting like the keyboard key in turn]
xkbset m
xkbset exp =m # keep the state unchanged after the AccessX timeout
xkbcomp "$DISPLAY" - |
sed -e 's/ Menu / Pointer_Button3 /' -e '/interpret KP_/,/};/d' |
xkbcomp - "$DISPLAY"
You can also bind another key combo to toggle the MouseKeys
controls. Eg. with Shift-Menu
:
xkbcomp "$DISPLAY" - |
sed -e 's/ Menu \| Pointer_Button3 / Pointer_Button3, MouseKeys_Enable /' -e '/interpret KP_/,/};/d' |
xkbcomp - "$DISPLAY"
This assumes that the Menu
key wasn't already rebound to something else.
Instead of xbkset
and xkbcomp
, you can easily write a small program to do the same thing (all operations they do can be done by any regular X11 client).
How to integrate this with ornery "desktop environments" (which change themselves the xkb settings based on their own rules) is left as an exercise to the reader.