Ubuntu – Custom keymapping via udev/hwdb.d is not working

keyboardkeyboard-layoutudev

Background: I got the Microsoft Natural Ergonomic Keyboard 4000 and several keys are not working at all under Ubuntu such as the F1-F10 keys. I have Ubuntu 14.04.2 LTS running on my machine.

My solution:
I created the file /etc/udev/hwdb.d/61-keyboard-local.hwdb and set up come custom rules:

keyboard:usb:v045ep00db*
 KEYBOARD_KEY_0x1008ff27=pageup
 KEYBOARD_KEY_0x1008ff26=pagedown
 KEYBOARD_KEY_0xff6a=F1
 KEYBOARD_KEY_0x1008ff6b=F5

I got the hex code through xev. For instance, for the key which should be the F1 key, xev returns

KeyRelease event, serial 37, synthetic NO, window 0x4400001,
    root 0xa2, subw 0x0, time 1746028, (12,-12), root:(61,40),
    state 0x10, keycode 146 (keysym 0xff6a, Help), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

After changing the file, I ran udevadm hwdb --update and udevadm trigger and, additionally, restarted my laptop.

Issue: The corresponding functionality is not assigned to the respective keys.

Best Answer

  • That one from xev is the key symbol keysym, here the idea:

    /keyboard/ → scancode → /input driver/ → keycode → /X server XKB/ → keysym

    man xev says: xev - print contents of X events

  • So, what you are looking for is the early hardware data from keyboard which is the scancode. It can be found using evtest

    man evtest evtest - Input device event monitor and query tool

    1. Install it

      sudo apt-get install evtest
      
    2. Run

      sudo evtest
      

      Output

      Event: time 1435906588.943349, type 4 (EV_MSC), code 4 (MSC_SCAN), value 3b
      Event: time 1435906588.943349, type 1 (EV_KEY), code 59 (KEY_F1), value 1
      

      Scancode is 3b