4

Object

I read this Arch wiki article to try to remap scancode & keycode on my Chakra 201710 + MacBook Pro 2015 (no touchbar and USB-C):

  1. Remap the built-in keyboard of like this:

    | ORIGINAL || capslock | control | option(alt) | command(meta?) |
    | MAP TO   || ctrl     | ctrl    | super       | alt            |
    
  2. Don't remap other external USB keyboard. (I never use an Apple external keyboard).

What I have tried (but failed, not works.)

1. Find the vendor id / product id / version of build-in keyboard

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.

Command:

less /proc/bus/input/devices

Got this:

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

So Apple built-in keyboard is evdev:input:b0003v05acp0274e0110*

2. Get scancodes

I used showkey --scancodes in TTY to get a default map like this:

|           | 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 |

I don't know why the scancode of all keys mentioned above are large than 1 byte...

3. Create config file in /etc/udev/hwdb.d/

Create file /etc/udev/hwdb.d/10-apple-kb.hwdb with following content:

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

Then reboot, not work...

Update: use evtest to capture scancode.

Take Caps Lock for example:

 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 ------------

So /etc/udev/hwdb.d/10-apple-kb.hwdb looks like this now:

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

Unfortunately, not work either...

Also try to use setkeycodes like this, it said error:

$ sudo setkeycodes 3aba 29
setkeycodes: failed to set scancode 3aba to keycode 29: ioctl KDSETKEYCODE: Invalid argument
  • those scancodes look odd. does evtest show the same scancodes? see wiki.archlinux.org/index.php/Extra_keyboard_keys#Scancodes – quixotic Dec 31 '17 at 8:55
  • Still not work. I clone latest evtest from cgit.freedesktop.org/evtest and build + installed. I just updated the situation in question. – kuanyui Jan 1 '18 at 17:41
  • those codes from evdev look saner. but your match line starts with a typo (gevdev:input should be evdev:input), hopefully this is just in the post? – quixotic Jan 2 '18 at 1:35
  • Yes, sorry just in post. Now question was updated. – kuanyui Jan 2 '18 at 2:18
  • Did you run systemd-hwdb update and the other command shown in the "60-keyboard.hwdb" file? – jarno Sep 2 '19 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.