29

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?

matanster
  • 2,294
  • 9
  • 36
  • 54
Dmitry Belaventsev
  • 303
  • 1
  • 3
  • 9
  • 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 04:37
  • any alternatives are welcome =) – Dmitry Belaventsev May 29 '14 at 04:47
  • Does [this](http://ubuntuforums.org/showthread.php?t=2182054&p=12821913#post12821913) help? – jobin May 29 '14 at 05:31
  • What does the no longer shipped `keymap` utility do anyway? – matanster 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
  • Possible duplicate of [how to get Microsoft Natural Ergonomic Keyboard 4000's zoom slider (and other buttons) to work?](https://askubuntu.com/questions/33038/how-to-get-microsoft-natural-ergonomic-keyboard-4000s-zoom-slider-and-other-bu) (both questions give valid but similar answers) – A.L Jan 30 '21 at 14:50

5 Answers5

38

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*

Adam Chýlek
  • 481
  • 5
  • 5
  • 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 05 '17 at 09:43
  • Thank you guys. Finally convinced my ancient Microsoft Corp. Digital Media Keyboard 1.0A to switch songs in Spotify. https://gist.github.com/mauron85/5f4b640aa4e5e968e0496ac5a0878715 – mauron85 Apr 19 '17 at 07:26
  • 1
    Works in Kubuntu 17.10 as well – OOPMan Dec 18 '17 at 08:29
28

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.

matanster
  • 2,294
  • 9
  • 36
  • 54
Oli
  • 289,791
  • 117
  • 680
  • 835
  • 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? – Dmitry Belaventsev Jun 01 '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 01 '14 at 14:26
  • 2
    unfortunately, doesn't make target button to work – Dmitry Belaventsev Jun 01 '14 at 16:43
  • device id was checked with `lsusb` as you mentioned – Dmitry Belaventsev Jun 01 '14 at 16:44
  • Hmm, looking at things again, the v:p codes might need to be caps. Try `keyboard:usb:v045Ep00DB*` – Oli Jun 01 '14 at 17:25
  • hmmm.. doesn't work for me too, even when changing lib/udev/hwdb.d/60-keyboard.hwdb itself. Interestingly, the zoom scroll doesn't zoom either, even though it _is_ picked up by `evtest` (at least in Chrome and Firefox). – matanster Sep 24 '14 at 21:42
  • Now it works! (Microsoft Natural Ergonomic Keyboard 7000, not 4000). Must have required that reboot after `sudo udevadm hwdb --update` even though the 7000 is not a PS/2 keyboard. Maybe `udevadm trigger` is necessary after the `update` but haven't tried that and you should read about that command before trying it, for myself I haven't used it before. – matanster Sep 24 '14 at 22:08
  • I tried everything on my 4000! I updated the hardware database and put the letters in all caps and everything! I noticed that before KEYBOARD_KEY (both times) there is a space. Would it help if I replaced that with a tab instead? – John Scott Dec 28 '14 at 22:55
  • BTW, any way of making it work for both keyboard models, with the same configuration? – matanster Jun 27 '15 at 07:35
  • 1
    @matt, you can put multiple aliases as [here](http://paste.ubuntu.com/11813942/) – user.dz Jul 03 '15 at 05:11
  • Oh great, good to know!! – matanster Jul 03 '15 at 10:52
  • On Debian Jessie 8.5 this didn't work. Answer below by @user261903 is the right choice in this case. – Nicolás Jul 11 '16 at 03:05
  • 2
    Instead of plugging|unpluging one can use `udevadm trigger /dev/input/by-id/usb-Microsoft-*` to trigger the update – Oleksandr Pryimak Jul 24 '17 at 22:55
  • I found the scrolling using _pageup_ and _pagedown_ key bindings to be too fast. Instead on can use _up_ and _down_ for a slower scrolling. – Ariel Aug 03 '17 at 14:16
7

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.

user261903
  • 71
  • 1
  • 2
4

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
r11
  • 73
  • 4
1

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