3

My laptop came with a PrintScreen key (on the right hand side of KB between to the Alt_R and Control_R). In Xorg, I've been using xmodmap to swap the printscreen with a menu key:

/usr/bin/xmodmap -e "keycode 107 = Menu"

Problem is that xmodmap, xdotool and anything else that relies on intercepting and injecting keystrokes doesn't work anymore on Wayland due to security restrictions. gnome-tweak-tool had (out of the box) a few nifty xkb based modifications that allowed swapping out some specific keys (like capslock with escape) but it didn't have the modification I was looking for.

I was wondering if there was a way of swapping the printscr for a menu key by modifying the keyboard layout files? Are they text files or are they binary files that I'd have to re-compile?

There's setkeycodes and getkeycodes in /usr/bin, does anyone know what these commands do?

2

Yes, it's possible to modify XKB files. I'd guess that the bottom of the /usr/share/X11/xkb/symbols/altwin file may give you a hint for your case - unless the XKB option altwin:prtsc_rwin does what you want.

Additional Info

In terminal, enter:

sudo su
nano /usr/share/X11/xkb/symbols/altwin

At the bottom of the file you will find:

// Win is mapped to the PrtSc key (and the usual Win key).
partial modifier_keys
xkb_symbols "prtsc_rwin" {
    replace key <PRSC> { [ Super_R, Super_R ] };
    modifier_map Mod4 { <PRSC>, <RWIN> };
};

Delete this section and replace it with this:

// Menu is mapped to the PrtSc key (and the usual Win key).
partial modifier_keys
xkb_symbols "prtsc_rwin" {
     replace key <PRSC> { [ Menu, Menu ] };
     modifier_map Mod4 { <PRSC>, <MENU> };
};

To delete in nano, use backspace key (highlighting and deleting doesn't work). To paste, use shift-ctrl-v. To exit and save, press ctrl-x, select yes to overwrite and press enter.

Reboot. In Gnome/Ubuntu Go to gnome-tweak-tools In tweak tools go to Keyboard & Mouse section, press the Additional Layout Options button and expand Alt/Win key behavior. Selecting the option on the very bottom: Win is mapped to printscr (remember that we've modified just this behavior to swap print and Menu instead of print and Win). (I'm sure there is a way of turning on the modded xkb option in KDE but I don't use it, so I can't give you the exact procedure).

  • You are seriously my hero! :) Do you mind if I edit your answer to expand on it? – thebunnyrules Jan 4 '18 at 3:04
  • @thebunnyrules: Great! No, of course I don't mind. I was vague simply because I was not sure... – Gunnar Hjalmarsson Jan 4 '18 at 3:05
  • Done. I've upvoted and marked it as the accepted answer. I think you need to allow the edit for it to show. Thanks again, having access to that button makes a big difference for me when I'm typing. – thebunnyrules Jan 4 '18 at 3:21
  • @thebunnyrules: Edits approved. Thanks for taking the time to share the detailed solution! – Gunnar Hjalmarsson Jan 4 '18 at 3:26
  • 1
    @thebunnyrules be aware this edit is to a system file, and will be overwritten by updates of the xkb-data package. keep a backup handy! – quixotic Jan 4 '18 at 7:57

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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