1

I want my Menu key on the keyboard (Keycode 135) to do the same as my right mouse button.

https://superuser.com/questions/336674/emulating-mouse-click-with-a-keyboard does that but it sacrifices the numpad region on my keyboard, so these keys no longer have their normal function. Since I use my keypad I am not interested in sacrificing that.

So I am looking for a solution that only touches the Menu button (Keycode 135).

1

[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.

1
  • Thanks, added that info. – mosvy Apr 6 '20 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.