I tried to use this tutorial to make scroll switch work on my Microsoft Natural Ergonomic Keyboard 4000. But I face following error:

sudo: /lib/udev/keymap: command not found

I have udev version 204-5ubuntu20.2 (the version found in Trusty)

I noticed that this version doesn't include keymap tool. But I notices that greater udev versions (which available for Debian, for example) include this tool.

Could somebody explain this diff for me? =) And what should I do in this case - install package from Debian repo?

  • Do you want to resolve this issue using udev or are you fine with alternatives? I would be a bit reluctant to install unpackaged udev debian packages on ubuntu. – jobin May 29 '14 at 4:37
  • any alternatives are welcome =) – dizpers May 29 '14 at 4:47
  • Does this help? – jobin May 29 '14 at 5:31
  • What does the no longer shipped keymap utility do anyway? – matt Sep 24 '14 at 22:04
  • I've updated my tutorial (that you linked to) to include the below answer. Thanks :-) – Terence Eden Nov 13 '14 at 11:28
up vote 27 down vote accepted
+100

If you look at /lib/udev/rules.d/60-keyboard.rules you'll see that everything has been messed around with. This is just part of the udev merger into systemd that has gone on.

All hardware rules are compiled into a binary hardware database. These follow a really strange format. The existing rules for keyboards that ship with udev live in /lib/udev/hwdb.d/60-keyboard.hwdb. Look at that but don't edit it (updates will probably overwrite it).

To add your custom rules, we'll create a new file in /etc/udev/hwdb.d/ by running sudoedit /etc/udev/hwdb.d/61-keyboard-local.hwdb. All you need to do is paste in the following -

If you are using the 4000 model:

keyboard:usb:v045Ep00DB*
 KEYBOARD_KEY_0c022d=pageup
 KEYBOARD_KEY_0c022e=pagedown

If you are using 7000 model:

keyboard:usb:v045Ep071D*
 KEYBOARD_KEY_0c022d=pageup
 KEYBOARD_KEY_0c022e=pagedown

This is adapated from the tutorial you posted so you might need to tweak based on your keyboard. Look at lsusb and make sure the vendor:product code above (as v####p####) is correct. It won't work if they don't match.

Once you're done editing, recompile the hwdb that udev uses:

sudo udevadm hwdb --update

And then you might need to re-plug. If it's a PS/2 keyboard you might need to reboot. In some cases you also need to reboot.

  • Thx for reply! hwdb.d dir is empty, rules.d contains only 3 files(70-persistent-cd.rules, 70-persistent-net.rules, README). So, did you mean that I must create a new file? Or I must have some to edit? – dizpers Jun 1 '14 at 12:05
  • Yeah you should be creating a new file. The existing keyboard rules are sitting in /lib/udev/hwdb.d/60-keyboard.hwdb but edits to it will be lost after udev updates. – Oli Jun 1 '14 at 14:26
  • 2
    unfortunately, doesn't make target button to work – dizpers Jun 1 '14 at 16:43
  • 1
    @matt, you can put multiple aliases as here – user.dz Jul 3 '15 at 5:11
  • 1
    Instead of plugging|unpluging one can use udevadm trigger /dev/input/by-id/usb-Microsoft-* to trigger the update – Alexandr Priymak Jul 24 '17 at 22:55

Ubuntu 15.10: I had no success with previous answers.

I have successfully used approach similar to the previous ones - instructions were mentioned in /lib/udev/hwdb.d/60-keyboard.hwdb.

I've created new hwdb file using sudo nano /etc/udev/hwdb.d/70-keyboard.hwdb containing:

# Microsoft Natural Ergonomic Keyboard 4000 - remap zoom in/out to page up/down
evdev:input:b0003v045Ep00DB*
 KEYBOARD_KEY_c022d=pageup
 KEYBOARD_KEY_c022e=pagedown

after that I've run

sudo udevadm hwdb --update
sudo udevadm control --reload

and replugged the keyboard and it worked.

For model 7000 use evdev:input:b003v045Ep071D*

  • 9
    This is correct answer for Ubuntu 16.04 – Greg Dan Apr 26 '16 at 10:43
  • 2
    Thanks. It indeed looks like the keyboard: definitions no longer work on Ubuntu 1604 and it needs to be evdev:. There is even a default mapping in /lib/udev/hwdb.d/60-keyboard.hwdb for the 4000 model that maps them to zoomin/zoomout - however X completely ignores the events (xev shows nothing) so you still need a configuration change like this. – wump Sep 19 '16 at 12:08
  • 2
    The b0003 looks like it's bus-specific (so it might only work in some USB ports). If something like b*v045Ep071D* works, that might be better. – Oli Dec 12 '16 at 14:23
  • 3
    Thanks, it's working in Ubuntu 16.04 (evdev:input:XXX instead of keyboard:usb:YYY). You can also use different mapping instead of pageup/pagedown. For example, I am using scrollup and scrolldown to do real scrolling. – Martin Grůber Jan 5 '17 at 9:43
  • 1
    Works in Kubuntu 17.10 as well – OOPMan Dec 18 '17 at 8:29

The original solution posted by Oli did not work for me, but it works after I changed the key numbers "0c022d" and "0c022e" to "c022d" and "c022e". I'm using a 4000 model, so I can't verify if the same change is needed for the 7000 model.

To repeat Oli's answer, here is what I did: create a new file by running sudo nano /etc/udev/hwdb.d/61-keyboard-local.hwdb. Paste the following lines to the file (for the 4000 model):

keyboard:usb:v045Ep00DB*
 KEYBOARD_KEY_c022d=pageup
 KEYBOARD_KEY_c022e=pagedown

After editing the file, recompile the hwdb that udev uses:

sudo udevadm hwdb --update

Then replug the keyboard.

  • Thanks. Oddly enough I needed to perform this change too now, and also a restart was required after it all (not just replugging). – matt Jun 28 '15 at 6:14
  • worked for me on Ubuntu 15.04. Thanks! – Pierre Aug 2 '15 at 7:41
  • This worked for me on Debian Jessie 8.5. – Nicolás Jul 11 '16 at 3:04
  • I want to buy an economic keyboard, and I am curious, whether it works with 16.04 LTS? Or there is not a problem like this there. – Arpad Horvath Aug 29 '16 at 10:15

Adding to Oli's answer, If you want line scrolling like how it is on a mouse, you can modify pageup/pagedown to up/down in your custom rule. Like:

keyboard:usb:v045Ep00DB*
 KEYBOARD_KEY_c022d=up
 KEYBOARD_KEY_c022e=down
  • By the way: Up/Down is default in 18.04. – LinuxLuigi Sep 24 at 12:14

Nice solution is here, and I can only add that you can map the keys to unused X keys like that:

$ cat /lib/udev/rules.d/95-keymap.rules
...
ENV{ID_VENDOR}=="Microsoft", ENV{ID_MODEL_ID}=="00db", RUN+="keymap $name 0xc022d katakana 0xc022e katakanahiragana
...

Proper names to use instead of katakana can be found here.

After reboot ;-) you can test that zoomin and zoomout keys are mapped successfully, and also to find out a proper names of the keys (to use in rc.xml for OpenBox WM, for example) using xev:

$ xev
...
KeyRelease event, serial 46, synthetic NO, window 0x3c00001,
    root 0x291, subw 0x0, time 1492891, (-261,-61), root:(573,380),
    state 0x0, keycode 101 (keysym 0xff27, Hiragana_Katakana), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False
...

Now you can connect new keys to completely arbitrary action. In my case of OpenBox window manager I used something like this:

$ cat <whatever>/rc.xml
...
<keybind key="Katakana">
  <action name="Execute">
    <command>volume_up.sh</command>
  </action>
</keybind>
<keybind key="Hiragana_Katakana">
  <action name="Execute">
    <command>volume_down.sh</command>
  </action>
</keybind>
...

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.