-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathusr_share_X11_xkb_to_hwdb.txt
40 lines (27 loc) · 2.47 KB
/
usr_share_X11_xkb_to_hwdb.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
XKB settings(/usr/share/X11/xkb/symbols/inet) only change event.key(keysyms in sudo xkbcli interactive-evdev) and won't change event.code(keycode in sudo xkbcli interactive-evdev),some web application will catch the original key code and re-emit original event.
For example in some customize monaco editor(google IDX development environment), if I remapped right-arrow key into right-control key(
key <RGHT> { [ Control_R ] };
in /usr/share/X11/xkb/symbols/inet), the google idx will re-emit a controlRight and a arrowRight, they happen to be a keyboard shortcut(word jumping).
So I shouldn't use xkb symbols file, and I shouldn't use "sudo setkeycodes e04d 97" ("sudo showkey -s" get "e04d" for right-arrow),
it will show error for usb keyboard: "setkeycodes: failed to set scancode cd to keycode 97: ioctl KDSETKEYCODE: Invalid argument",
I can only use /etc/udev/hwdb.d/10-myboard.hwdb(or /usr/lib/udev/hwdb.d/10-myboard.hwdb):
evdev:input:b0003v046Dp4024*
KEYBOARD_KEY_7004f=97
"7004f" is the rightArrow scancode in "sudo evtest /dev/input/event?".
"97" or "KEY_RIGHTCTRL" is from the "sudo evtest" or "grep -i right /usr/include/linux/input-event-codes.h"
and then exec:
sudo systemd-hwdb update ; sudo udevadm control --reload-rules ;sudo udevadm trigger
finally, test it with "sudo evtest", and the key code has been changed from 106 to 97. And the problem in google IDX monaco editor has been resolved.
scancode(7004f, KeyboardRightArrow) --> keycode(106, KEY_RIGHT) --> keysyms(97, Control_R)
linux内核默认映射scancode --> keycode, 例如: 7004f(KeyboardRightArrow) --> 106(KEY_RIGHT)
linux内核默认映射代码: https://github.com/torvalds/linux/blob/master/drivers/hid/hid-input.c 里面的 static const unsigned char hid_keyboard[256] = { ... } 映射表
比如 hid_keyboard[256] 第5行第16列 编号就是4f, 则scancode就是7004f, 映射表该位置的值是十进制的106就是keycode
ref:
scancode名称可以查: https://github.com/torvalds/linux/blob/master/drivers/hid/hid-debug.c#L380
{ 0x07, 0x004f, "KeyboardRightArrow" },
keycode名称可以查: grep -i 106 /usr/include/linux/input-event-codes.h
#define KEY_RIGHT 106
用 keysym名称 查 X keycode(把x keycode减去8就是linux keycode): grep -i rctl /usr/share/X11/xkb/keycodes/evdev
<RCTL> = 105;
查看keysym名称 与 keysym短名称 对应关系: grep -Rin 'Control_R ]' /usr/share/X11/xkb/symbols/pc
详见: https://github.com/diyism/MyBoard/blob/master/usr_share_X11_xkb_showkeys.sh