Remap a key so that it actually works on Plasma6 wayland...

Hello!

I’m new to both wayland and KDE, not new to Linux though.
Previously I liked to map the PrtSc (seen on the pic; this kb does not have a dedicated menu key) to the Menu key, i.e. I could pop up the context menu of a selected item with a key. On this same machine, under Xorg/Openbox.

It’s a Thinkpad T430s. In System Settings => keyboard it was first configured as a generic 104 key PC keyboard, now as a generic 105 key PC keyboard (just to try something I hadn’t tried yet).

localectl
System Locale: LANG=en_GB.UTF-8
               LC_NUMERIC=en_IE.UTF-8
               LC_TIME=en_IE.UTF-8
               LC_MONETARY=en_IE.UTF-8
               LC_PAPER=en_IE.UTF-8
               LC_NAME=en_IE.UTF-8
               LC_ADDRESS=en_IE.UTF-8
               LC_TELEPHONE=en_IE.UTF-8
               LC_MEASUREMENT=en_IE.UTF-8
               LC_IDENTIFICATION=en_IE.UTF-8
    VC Keymap: fi
   X11 Layout: fi
    X11 Model: pc105

I cannot get this to work. What I tried:

1: create ~/.config/xkb/symbols/fi:

partial alphanumeric_keys
xkb_symbols "menu" {
    name[Group1]= "Menu (FI)";
    include "fi(fi)"
    key <PRSC> { [ Menu ] };
};

log out/in - I cannot get the desired outcome (tested in Dolphin and Librewolf browser)

2: create /etc/udev/hwdb.d/99-builtin-keyboard-remap-prtsc.hwdb:

evdev:name:AT Translated Set 2 keyboard:*
 KEYBOARD_KEY_b7=menu

I checked with evtest; this is the correct hex keycode and hopefully the correct menu key.

evtest seems to indicate that this worked:

Event: time 1789412840.200682, type 4 (EV_MSC), code 4 (MSC_SCAN), value b7
Event: time 1789412840.200682, type 1 (EV_KEY), code 139 (KEY_MENU), value 1

(Before it registered as SYSRQ or SYS_RQ)

I rebooted just to be sure.

But again, it doesn’t.

I tried to log into a labwc session and installed pcmanfm (simpler filemanager), even under a different user. I can never get this key to pop up the context menu.

3: ydotool

Just to be sure, I undid the hwdb tweaking, rebooted, and told ydotool to press & release the menu key:

sleep 5; ydotool key -d 100 139:1 139:0

and sitched to a Dolphin or Librewolf window - nothing.

Lastly, I checked in System Settings => Keyboard => Keybindings => Miscellaneous options => Use user-defined custom XKB types, reinstated the file from 1: and logged out/in - still nothing.

Am I missing something here?

TIA

Have you tried input-remapper?

Tony

You can go to System Settings > Keyboard and change the shortcuts for Spectacle (the screen capture tool) from there, rather than entirely remapping the keyboard keys.

If I correctly understand what you’re doing (and want to work), I would expect your step 2 alone to achieve it.

localectl

note that what you see with localectl is the system wide default, which

  • can be overriden by KDE’s system settings
  • to my knowledge can not load anything from a users home

~/.config/xkb/symbols/fi

Are you sure that you can just override keymaps that way? When I defined my custom layout, I created a symbols file with a unique name, created a ~/.config/xkb/rules/evdev.xml file with an entry for it, then selected it in KDE’s keyboard layout dialog.
Also this would not have any effect after step 2, because PRSC already is Menu.


What is the output of wev?

Thanks to all!

I forgot to mention my distro: CachyOS (ARCH based). I cannot edit my OP.

@Tony_Brown Not yet.

@Dan1 This is about having a dedicated Menu key on a keyboard that doesn’t have one. I already assigned a different key combo for launching Spectacle.

Yes! And in a way it does, as my evtest tests show, but the change doesn’t have the desired effect.
So with this option 2: active (and no other) I tested with wev:

[        16:     wl_keyboard] key: serial: 89190; time: 49953685; key: 147; state: 1 (pressed)
                      sym: XF86MenuKB   (269025125), utf8: ''
[        16:     wl_keyboard] key: serial: 89191; time: 49953827; key: 147; state: 0 (released)
                      sym: XF86MenuKB   (269025125), utf8: ''

So now it’s key 147? That is very confusing. evtest said 139.
This corresponds to the numbers in the kernel header file input-event-codes.h, but 147 does not.

I had partial succes btw; I can customise “Open Context Menu” in System Settings => Shortcuts => View. Good, but this applies only to Plasma apps (not e.g. any of the browsers).

I noticed a weird thing:
This shortcut was already set to the Menu key by default. Which doesn’t work with the manipulation in point 2: of my first post.
So I unset the default and added the ex-PrtSc-now-Menu key.
Strangely, it shows up as “Keyboard Menu” and not “Menu”.

Hmm, apparently I have to gather some kudos before I can edit my posts.

I forgot to mention that I even rebooted into a Xorg-based Live Linux session and was able to make it work with the hwdb method.

So now it’s key 147? That is very confusing. evtest said 139.
This corresponds to the numbers in the kernel header file input-event-codes.h, but 147 does not.

Evtest shows the evdev-keycode, while wev shows the xkb-keycode which is the evdev-keycode + 8, so this is expected behaviour.

What is interesting though is where it differs from my output:

[14:     wl_keyboard] key: serial: 13315; time: 2924352; key: 135; state: 1 (pressed)
                      sym: Menu         (65383), utf8: ''
[14:     wl_keyboard] key: serial: 13316; time: 2924431; key: 135; state: 0 (released)
                      sym: Menu         (65383), utf8: ''

Key 135 is 127, aka KEY_COMPOSE, in evdev. This is unexpected… but it seems, you need to set your hwdb-rule to compose for this to work in wayland…

Yeah, there is some confusing nomenclature here.

The HID code page defines “Keyboard Menu” (0x76) and “Keyboard Application” (0x65).

Contrary to what you might expect, the ‘menu’ key on most keyboards corresponds to “Keyboard Application” not “Keyboard Menu”.

I haven’t traced these through to the evdev and X11 keycodes, but it certainly seems like it would be easy to get tripped up on nomenclature when looking for the right code.

Thank you!

I have edited
/etc/udev/hwdb.d/99-builtin-keyboard-remap-prtsc.hwdb

evdev:name:AT Translated Set 2 keyboard:*
 KEYBOARD_KEY_b7=compose

And executed

systemd-hwdb update
udevadm trigger

Now the PrtScr key is the menu key, in all applications.