9

I have a Lenovo Yoga 710 where the 'Up' key is in the place where the shift key should be. Unfortunately this laptop won't run earlier kernels because it has "new" hardware. I see the mechanism to remap keys in Wayland (GNOME) here: https://superuser.com/questions/1196241/how-to-remap-caps-lock-on-wayland

But, I can't find the xkb-options code for "Up" anywhere. "Right shift" might be "rshift" according to /usr/share/X11/xkb/rules/base. Where is the list of xkb-options key names and/or what are the names for the 'right shift key' and the 'Up' key?

1
  • If you want to remap your keyboard keys or mouse buttons to certain keys, use "Input Remapper" by sezanzeb. It's VERY simple, it has a GUI, and it just WORKS. I just have set a certain shortcut to simulate a keyboard key, works well.
    – Allexj
    Commented Jan 7, 2023 at 12:55

3 Answers 3

10

After around 2 days of googling an answer to the question "how to remap keys on wayland" I have managed to find a very, very simple way. I dont know if its the right way but it actually works.

The only thing that I had to do is open the file

/usr/share/X11/xkb/keycodes/evdev

That file lists all the keycodes for all the keys in the form < code > = number

You can simply swap the keycodes around. What I actually swapped around is the numbers NOT the code. I changed backslash which on dvorak is next to Enter with Ctrl for Emacs.

edit: to find out which "code" represents each key as in < code > = number you can run the xev command from the terminal to get the keycode printed in the terminal after pressing the button (search for that keycode in the evdev file to get the evdev scancode for the key), or you can visit

/usr/share/X11/xkb/symbols/

This is a directory which has one file for each language installed on the computer and modifier keys. Select the language your pc runs on.

In that file there will be all variants supported listed, such as dvorak, programmers dvorak, colemans etc etc.

There you can see the < code > names

6
  • Thank you. Worked perfectly on Fedora too :)
    – jeremyh
    Commented Jun 14, 2020 at 3:59
  • Some lines look like <I171> = 171; // #define KEY_NEXTSONG 163. How should lines like these be edited, specically the define section?
    – Flimm
    Commented Jul 22, 2021 at 12:16
  • Appears to require logging out (or restarting the system). I was able to remove the entire line for the corresponding key. Fedora 34 on Wayland.
    – user598527
    Commented Oct 6, 2021 at 17:29
  • Could you give the actual example of what you changed and what it achieved exactly? I can't seem to make two keys equal. I'd like to remap the key 135 or <COMP> to key 108 or <RALT>. I've tried various ways of changing either the <code> or <number> but I can't seem to make the two keys equal. Anybody has an idea? Thanks
    – elkevn
    Commented Oct 16, 2022 at 15:21
  • If you want to remap your keyboard keys or mouse buttons to certain keys, use "Input Remapper" by sezanzeb. It's VERY simple, it has a GUI, and it just WORKS. I just have set a certain shortcut to simulate a keyboard key, works well.
    – Allexj
    Commented Jan 7, 2023 at 12:55
4

Right now customizing keys is a bit tricky when using Wayland: https://unix.stackexchange.com/questions/292868/how-to-customise-keyboard-mappings-with-wayland

But if you just want to remap a key so that it should function as another key, the command setkeycodes seems to work.

Run sleep 1; showkey -s in the terminal as root, and then press the key Up once, and then wait 10 seconds

root@laptop:~# sleep 1; showkey -s
kb mode was ?UNKNOWN?
[ if you are trying this under X, it might not work
since the X server is also reading /dev/console ]

press any key (program terminates 10s after last keypress)...
^[[A0xe0 0x48 
0xe0 0xc8 
root@laptop:~# 

From the output we see that 0xe0 0x48 is the scan code for the key Up.

Run sleep 1; showkey -k in the terminal as root, and then press the key Right shift once, and then wait 10 seconds

root@laptop:~# sleep 1; showkey -k
kb mode was ?UNKNOWN?
[ if you are trying this under X, it might not work
since the X server is also reading /dev/console ]

press any key (program terminates 10s after last keypress)...
keycode  54 press
keycode  54 release
root@laptop:~# 

From the output we see that 54 is the key code for the key Right shift.

To remap the Up key to the Right shift key, run setkeycodes 0xe048 54 in the terminal as root.

root@laptop:~# setkeycodes 0xe048 54

The scan code was previously printed as 0xe0 0x48, but now when it was given as an input argument to setkeycodes, it was written 0xe048.

3
  • 1
    is this persistent through reboots? is there a process for resetting things back to normal?
    – Ace
    Commented Mar 2, 2018 at 12:23
  • 1
    A reboot will give you back the original key mapping. I usually run the setkeycodes command after each reboot. Commented Mar 2, 2018 at 16:24
  • Unfortunately, setkeycodes does not work with USB keyboards (Linux 6.2, Ubuntu 23.04). Thank you very much, anyway!
    – Ganton
    Commented Jun 21, 2023 at 9:30
1

I was able to do it using https://github.com/sezanzeb/input-remapper, which I installed via Ubuntu Software (aka SnapStore).

Using Ubuntu 22.04, Gnome 42.2, Wayland.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .