The procedure is not best described elsewhere on the web. This article is a mess, too, but it works for me.
Keys need to be remapped to something under keycode 256 in order to work under X11.
- Try using
evtest
and pressing keys to see what the keys map to right now.evtest
can will also tell you what are all the events supported by the device.evtest
will show two devices; you are interested in the second one (which exposes all the extended keys, such asnew
,reply
,open
,send
, etc.
- Use
xev
to see whether the keys are recognized, and as what are they recognized, in X11.
Now for the juicy part:
# put this into: /etc/udev/hwdb.d/61-keyboard-custom.hwdb # then to update: # sudo udevadm hwdb --update && sudo udevadm control --reload-rules && sudo udevadm control --reload # and: # sudo udevadm trigger # or: # for i in /sys/class/input/* ; do if [[ -e "$i"/id/vendor ]] && [[ -e "$i"/id/product ]] && [[ "$(cat "$i"/id/vendor)" == 045e ]] && [[ "$(cat "$i"/id/product)" == 00db ]] ; then echo $i ; echo change | sudo tee $i/uevent ; fi ; done # Natural Keyboard 4000 # formerly: #keyboard:usb:v045Ep00DB* # now: evdev:input:b0003v045Ep00DB* KEYBOARD_KEY_0c01ab=finance # KEY_SPELLCHECK to KEY_FINANCE KEYBOARD_KEY_c022d=up KEYBOARD_KEY_c022e=down
We’re naming it 61-keyboard-custom.hwdb
in order to have it come after /lib/udev/hwdb.d/60-keyboard.hwdb
.
Instead of finance
, up
and down
keys, try taking something from this list: quirk-keymap-list.txt — however, I am not certain how to determine which ones are under 256 except by looking at evtest
‘s output.
You can map to keycode 255 and use xmodmap -e "keycode 255 = XF86ZoomIn"
to map to a ‘proper’ zoom in key.
On a related note: If you want to remap scancodes to keycodes, you can do it on the fly using setkeycodes(8)
Some sources:
- http://marcin.juszkiewicz.com.pl/2014/03/03/how-to-get-zoom-slider-on-microsoft-keyboard-recognized-by-x11/
- https://unix.stackexchange.com/q/39370
EDIT 2021-01-27:
- Another useful resource is Arch Linux wiki’s article on mapping the scancodes.
- Config files mapping from scancodes to X keycodes can be found in
/usr/share/X11/xkb/keycodes
. For instance, scancodes generated by evdev are in the fileevdev
in that directory. - Scancodes can be found using
showkey
— which only works from the virtual console, not from within X11.