目的
我读这篇 Arch 维基文章尝试在我的 Chakra 201710 + MacBook Pro 2015(无触摸栏和 USB-C)上重新映射扫描码和键码:
重新映射内置键盘像这样的:
| ORIGINAL || capslock | control | option(alt) | command(meta?) | | MAP TO || ctrl | ctrl | super | alt |
不要重新映射其他外部 USB 键盘。(我从不使用苹果外接键盘)。
我已经尝试过(但失败了,不起作用。)
1.查找内置键盘的供应商ID/产品ID/版本
https://github.com/systemd/systemd/blob/master/hwdb/60-keyboard.hwdb
# - Generic input devices match:
# evdev:input:bZZZZvYYYYpXXXXeWWWW-VVVV
# This matches on the kernel modalias of the input-device, mainly:
# ZZZZ is the bus-id (see /usr/include/linux/input.h BUS_*), YYYY, XXXX and
# WWW are the 4-digit hex uppercase vendor, product and version ID and VVVV
# is an arbitrary length input-modalias describing the device capabilities.
# The vendor, product and version ID for a device node "eventX" is listed
# in /sys/class/input/eventX/device/id.
命令:
less /proc/bus/input/devices
收到:
I: Bus=0003 Vendor=05ac Product=0274 Version=0110
N: Name="Apple Inc. Apple Internal Keyboard / Trackpad"
P: Phys=usb-0000:00:14.0-12/input1
S: Sysfs=/devices/pci0000:00/0000:00:14.0/usb1/1-12/1-12:1.1/0003:05AC:0274.0004/input/input7
U: Uniq=D3H624316K1FTV4A63PS
H: Handlers=sysrq kbd leds event7
B: PROP=0
B: EV=120013
B: KEY=10000 0 0 0 1007b00011007 ff9f217ac14057ff ffbeffdfffefffff fffffffffffffffe
B: MSC=10
B: LED=1f
所以苹果内置键盘是evdev:input:b0003v05acp0274e0110*
2. 获取扫描码
我showkey --scancodes
在 TTY 中使用了这样的默认地图:
| | scancode (hex) | keycode |
|-----------+----------------+---------|
| capslock | 3a ba | 58 |
|-----------+----------------+---------|
| fn | -- -- | 464 |
| leftctrl | 1d 9d | 29 |
| leftalt | 38 b8 | 56 |
| leftmeta | e0 5b e0 db | 125 |
|-----------+----------------+---------|
| rightctrl | e0 5c e0 dc | 126 |
| rightalt | e0 38 e0 b8 | 100 |
我不知道为什么
scancode
上面提到的所有键都大于 1 个字节......
3. 创建配置文件/etc/udev/hwdb.d/
创建/etc/udev/hwdb.d/10-apple-kb.hwdb
包含以下内容的文件:
evdev:input:b0003v05acp0274e0110*
KEYBOARD_KEY_3aba=leftctrl
KEYBOARD_KEY_1d9d=leftctrl
KEYBOARD_KEY_38b8=leftmeta
KEYBOARD_KEY_e05be0db=leftalt
KEYBOARD_KEY_e05ce0dc=rightctrl
KEYBOARD_KEY_e038e0b8=rightalt
然后重启就不行了...
更新:用于
evtest
捕获扫描码。举
Caps Lock
个例子:Event: time 1514827961.426158, -------------- SYN_REPORT ------------ Event: time 1514827961.538086, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70039 Event: time 1514827961.538086, type 1 (EV_KEY), code 58 (KEY_CAPSLOCK), value 0 Event: time 1514827961.538086, -------------- SYN_REPORT ------------
现在
/etc/udev/hwdb.d/10-apple-kb.hwdb
看起来像这样:evdev:input:b0003v05acp0274e0110* KEYBOARD_KEY_70039=leftctrl KEYBOARD_KEY_700e0=leftctrl KEYBOARD_KEY_700e2=leftmeta KEYBOARD_KEY_700e3=leftalt KEYBOARD_KEY_700e7=rightctrl KEYBOARD_KEY_700e6=rightalt
不幸的是,也不起作用......
也尝试setkeycodes
这样使用,它说错误:
$ sudo setkeycodes 3aba 29
setkeycodes: failed to set scancode 3aba to keycode 29: ioctl KDSETKEYCODE: Invalid argument