How to remap key in Ubuntu 17.10 Wayland? (Up key to Shift)
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?
Solution 1:
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
Solution 2:
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
.