I have an external keyboard connected by USB on my laptop. I would like to remap the keycodes of the external keyboard without changing the keycodes of the laptop keyboard.
To be more specific, I want the function keys (F1-F12) to behave as they are, not the functionalities like turning volume/brightness up/down.
Let's use F12 as example. When I'm focusing on Chrome,
Laptop keyboard : F12 -> open console
FN+F12 -> volume up
External keyboard: F12 -> volume up
FN+F12 -> open console
It is totally messed up. When I use xev, here's the output:
External keyboard (xev)
----------------------------------------
[F11] (volume down)
FocusOut event, serial 33, synthetic NO, window 0x4000001,
mode NotifyGrab, detail NotifyAncestor
FocusIn event, serial 33, synthetic NO, window 0x4000001,
mode NotifyUngrab, detail NotifyAncestor
KeymapNotify event, serial 33, synthetic NO, window 0x0,
keys: 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[F12] (volume up)
FocusOut event, serial 33, synthetic NO, window 0x4000001,
mode NotifyGrab, detail NotifyAncestor
FocusIn event, serial 33, synthetic NO, window 0x4000001,
mode NotifyUngrab, detail NotifyAncestor
KeymapNotify event, serial 33, synthetic NO, window 0x0,
keys: 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[FN+F12]
KeyPress event, serial 33, synthetic NO, window 0x4000001,
root 0x5d1, subw 0x0, time 16400865, (-850,446), root:(706,511),
state 0x0, keycode 96 (keysym 0xffc9, F12), same_screen YES,
XLookupString gives 0 bytes:
XFilterEvent returns: False
KeyRelease event, serial 33, synthetic NO, window 0x4000001,
root 0x5d1, subw 0x0, time 16400985, (-850,446), root:(706,511),
state 0x0, keycode 96 (keysym 0xffc9, F12), same_screen YES,
XLookupString gives 0 bytes:
XFilterEvent returns: False
As you can see, F11 (volume down) and F12 (volume up) have no difference in xev. But in acpi_listen, I have
External keyboard (acpi_listen)
----------------------------------------
[F11]
button/volumedown VOLDN 00000080 00000000 K
----------------------------------------
[F12]
button/volumeup VOLUP 00000080 00000000 K
xinput -list of the external keyboard (not sure why there are 2 entries)
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ ...
↳ SONiX USB DEVICE id=13 [slave keyboard (3)]
↳ SONiX USB DEVICE id=23 [slave keyboard (3)]
How can I change the key mapping of the external keyboard without interfering with the laptop keyboard? The external keyboard does not have 'FN-lock' or anything like that.
PS: Actually, the Windows key and left Alt key have swapped, but I assume if the problem above is solved, this will be too.
PS 2: I have read this, but it only changes the layout of the keyboard to another predefined layout mapping, which doesn't solve my problem.
I'm on Ubuntu 20.04 and kernel 5.4.0-33-generic. My laptop is an Asus UX550.