How can I make KDE plasma to recognize Left ⌘ key as Left Meta?

Hi, I’m using USB HHKB Pro2 keyboard. I want to use ⌘ key as Meta, but KDE seems to recognize it as Muhenkan or Henkan_Mode keys.

Here is the xev output when I pressed Left ⌘ and Right ⌘ in a row.

KeyPress event, serial 39, synthetic NO, window 0x1200001,
    root 0x49a, subw 0x0, time 3530941, (89,97), root:(960,540),
    state 0x0, keycode 102 (keysym 0xff22, Muhenkan), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 39, synthetic NO, window 0x1200001,
    root 0x49a, subw 0x0, time 3531149, (89,97), root:(960,540),
    state 0x0, keycode 102 (keysym 0xff22, Muhenkan), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyPress event, serial 39, synthetic NO, window 0x1200001,
    root 0x49a, subw 0x0, time 3534053, (89,97), root:(960,540),
    state 0x0, keycode 100 (keysym 0xff23, Henkan_Mode), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 39, synthetic NO, window 0x1200001,
    root 0x49a, subw 0x0, time 3534173, (89,97), root:(960,540),
    state 0x0, keycode 100 (keysym 0xff23, Henkan_Mode), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

I used xkbcomp to display the current keysyms mapped to Muhenkan or Henkan_Mode.

$ xkbcomp $DISPLAY - 2>/dev/null | grep 'enkan'
    key <HENK> {         [     Henkan_Mode ] };
    key <MUHE> {         [        Muhenkan ] };

Then I replaced Muhenkan to Super_L and Henkan_Mode to Super_R with the following command.

$ xkbcomp $DISPLAY - 2>/dev/null | sed -e 's/Muhenkan/Super_L/g; s/Henkan_Mode/Super_R/g' | xkbcomp - $DISPLAY 2>/dev/null

Now keysym <MUHE> is mapped to Super_L, and <HENK> is mapped to Super_R.

$ xkbcomp $DISPLAY - 2>/dev/null | grep 'Super_'
    interpret Super_L+AnyOf(all) {
    interpret Super_R+AnyOf(all) {
    interpret Super_L+AnyOfOrNone(all) {
    interpret Super_R+AnyOfOrNone(all) {
    key <HENK> {         [         Super_R ] };
    key <MUHE> {         [         Super_L ] };
    key <SUPR> {         [        NoSymbol,         Super_L ] };

I also confirmed that xev is now showing the correct output when I pressed Left ⌘ and Right ⌘.

KeyPress event, serial 39, synthetic NO, window 0x1200001,
    root 0x49a, subw 0x0, time 4306067, (21,61), root:(892,504),
    state 0x0, keycode 102 (keysym 0xffeb, Super_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 39, synthetic NO, window 0x1200001,
    root 0x49a, subw 0x0, time 4306235, (21,61), root:(892,504),
    state 0x40, keycode 102 (keysym 0xffeb, Super_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyPress event, serial 39, synthetic NO, window 0x1200001,
    root 0x49a, subw 0x0, time 4306379, (21,61), root:(892,504),
    state 0x0, keycode 100 (keysym 0xffec, Super_R), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 39, synthetic NO, window 0x1200001,
    root 0x49a, subw 0x0, time 4306451, (21,61), root:(892,504),
    state 0x40, keycode 100 (keysym 0xffec, Super_R), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

However, KDE is still recognizing Left ⌘ as Muhenkan when I tried to add some shortcuts with ⌘ modifier.

I also tried remapping with xmodmap using the following command, but the results are the same.

cat <<\EOF >> ~/.Xmodmap
keycode 102 = Super_L
keycode 100 = Super_R
EOF

xmodmap ~/.Xmodmap

How can I make KDE to correctly recognize the XKB or xmodmap remappings?

Here is my KDE’s system info.

Operating System: Debian GNU/Linux 12
KDE Plasma Version: 5.27.5
KDE Frameworks Version: 5.103.0
Qt Version: 5.15.8
Kernel Version: 6.1.0-27-amd64 (64-bit)
Graphics Platform: Wayland
Processors: 4 × Intel® Core™ i3-8100 CPU @ 3.60GHz
Memory: 15.3 GiB of RAM
Graphics Processor: Mesa Intel® UHD Graphics 630

Looking for someone’s help.

Definitely not an expert here myself, but some things that might be helpful that I’ve found along the way:

Why Wayland works differently than X11 when it comes to keyboard mapping: Does Wayland use XKB for keyboard layouts? - Unix & Linux Stack Exchange

Some remapping options are available in the KDE Plasma System Settings application, under Keyboard > Key Bindings (this may look different on your system as Debian, by design, uses an older out-of-support version of KDE Plasma).

Since you’re not afraid of getting into some command-line tools, this guide to using udev to pull off remappings at a much lower level of the system may be helpful: https://www.reddit.com/r/linux_gaming/comments/nypsi1/updated_guide_to_remapping_keys_on_linux_using/

Hope this helps in the meantime,

Hi, I’ve finally made my ⌘ key working with the following settings:

  1. Turn on the DIP Switch 1 (Lite Ext. mode) and 3 (Delete = ‘BS’)
  2. Open the Advanced tab in keyboard setting and select the checkbox Alt and Win behavior > Alt is swapped with Win

This is the easiest workaround to make HHKB Pro2 keyboard work well without any tricky hacking, and hope this helps other HHKB users also struggling with the ⌘ key remapping.

1 Like