7

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?

  • 1
    you'll need to use XKB options and layouts; xmodmap and X-related tools like setxkbmap will not work with Wayland. possibly duplicate of https://unix.stackexchange.com/q/292868/222377 – quixotic Jan 03 '18 at 07:52
  • Yes, I've actually read through that post a week ago, the main answer was xkb but xkb doesn't do printscr/menu out of the box. Someone on another thread gave me a suggestion of modifying xkb's config files and I did just that. seems to work like a charm. I'll be posting it here as answer. – thebunnyrules Jan 04 '18 at 03:42

1 Answers1

5

As I've stated in my question, there is already xkb which already has alot options for modifying the keyboard. It wasn't an option for me because the only option to modify the printscr key, replaced it with Win_R. Gunnar Hjalmarsson on this thread suggested to me that I modify xkb's modifications so that the printscr/win_r would do printscr/menu instead. We worked out a solution together and I'm going to retransmit it here:

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

  • Note that if you modify stuff in /usr/share/X11/xkb, the changes will be undone the next time you upgrade the xkb software package, and you'll affect all keyboard layouts using those files. The "proper", bulletproof way (which needs more work) is to add your own layout using new files, without modifying the existing files. – dirkt Jan 04 '18 at 08:50
  • I'm on a laptop so I wasn't too worried about other KBs but you make a good point about xkb updates overwriting the mod. How would I go about modifying the layout? If you know how, could you put it up as an answer? – thebunnyrules Jan 07 '18 at 02:04
  • Menu is not normally a modifier key, so you shouldn't leave the modifier_map line in the alteration. – quixotic Feb 05 '18 at 19:36
  • I'll give it a try and edit my answer accordingly if I see that it works. What does taking out the modifier_map line do? – thebunnyrules Feb 07 '18 at 23:11
  • @quixotic I tested out your suggestion and have updated my answer. Out of curiosity, are there any consequences from leaving the modifier_map line? – thebunnyrules Feb 21 '18 at 02:59
  • @thebunnyrules in the original, the modifier_map line is used to keep both the original Win key and the PrSc-as-Win key mapped to Mod4. keeping that line will map the Mod4 modifier to PrSc-as-Menu and Menu, which is certainly not part of the Menu key's normal definition. if you have problems with your Win keys acting funny or your Menu keys acting like Win keys, that line is why. – quixotic Feb 21 '18 at 19:41