how to get Microsoft Natural Ergonomic Keyboard 4000's zoom slider (and other buttons) to work?

Create the file /etc/udev/rules.d/98-ms-ergo.rules with the following contents:

ACTION=="remove", GOTO="keyboard_end"
KERNEL!="event*", GOTO="keyboard_end"
ENV{ID_INPUT_KEY}=="", GOTO="keyboard_end"
SUBSYSTEMS!="usb", GOTO="keyboard_end"

SUBSYSTEMS=="usb", IMPORT{builtin}="usb_id"

ENV{ID_VENDOR}=="Microsoft", ENV{ID_MODEL_ID}=="00db", RUN+="keymap $name 0xc022d pageup 0xc022e pagedown"

GOTO="keyboard_end"

This will map the zoom key to page-up/page-down without changing the installed files in /lib/udev.

Once added, you just need to unplug and replug your keyboard for it to start working.


On Xubuntu 13.10 (perhaps on Ubuntu 13.10 too) the same can be done as follows:

Edit key mappings in /lib/udev/hwdb.d/60-keyboard.hwdb:

###########################################################
# Microsoft
###########################################################

# Microsoft Natural Ergonomic Keyboard 4000
keyboard:usb:v045Ep00DB*
 KEYBOARD_KEY_c022d=pageup
 KEYBOARD_KEY_c022e=pagedown

Run sudo udevadm hwdb --update

Reboot.


In order to configure the Microsoft ergonomic keyboard 4000 we have to create a configuration file that contains the keyboard declaration and the records for mapping the keys.

To do so there are three types of information we need to determine:

  • Keyboard type
  • The key scancode which is the actual key on the keyboard
  • The key name to assign the desired functionality to the selected key

First find the keyboard type:

In terminal run the following command:

lsusb 

the output determines the keyboard type:

...
Bus 004 Device 022: ID 045e:00db Microsoft Corp. Natural Ergonomic Keyboard 4000 V1.0
...    

It appears after ID. In this case it is 045e:00db

Second find the scancode and the name of the key.

To determine them, we use the evtest program which logs out the event information of a specific device on terminal:

evtest

If you don't have the program, install it by running the following command:

sudo apt-get install evtest

By running the evtest program we get the following output:

No device specified, trying to scan all of /dev/input/event* Available devices: 
/dev/input/event0:    Power Button     
/dev/input/event1:    Power Button     
/dev/input/event2:    PixArt USB Optical Mouse   
/dev/input/event3:    Microsoft Natural® Ergonomic Keyboard 4000   
/dev/input/event4:    Microsoft Natural® Ergonomic Keyboard 4000   
/dev/input/event5:    HDA Intel Front Headphone     
/dev/input/event6:    HDA Intel Line Out     
/dev/input/event7:    HDA Intel Line   
/dev/input/event8:    HDA Intel Rear Mic     
/dev/input/event9:    HDA Intel Front Mic     
/dev/input/event10:   HDA ATI HDMI HDMI/DP,pcm=3
Select the device event number [0-10]:

The output is pretty much self explanatory, insert the appropriate number for the keyboard, which here is number 3 then hit enter:

Doing so, will output lots of information on the terminal and ends in following lines:

... 

Testing ... (interrupt to exit)
Event: time 1472203902.240594, type 17 (EV_LED), code 0 (LED_NUML), value 0
Event: time 1472203902.240594, -------------- SYN_REPORT ------------
Event: time 1472203902.281456, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70058
Event: time 1472203902.281456, type 1 (EV_KEY), code 96 (KEY_KPENTER), value 0
Event: time 1472203902.281456, -------------- SYN_REPORT ------------

Now with every key-press on the keyboard it dumps out the key information. For example the Slash key next to the Right Shift shows:

Event: time 1472205062.294078, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70038
Event: time 1472205062.294078, type 1 (EV_KEY), code 12 (KEY_SLASH), value 0
Event: time 1472205062.294078, -------------- SYN_REPORT ------------

The first line of the log contains the information about the actual key on the keyboard such as scancode which comes after the value. In this case it is 70038

The second line contains the assigned functionality information like name of the key. In this case it is SLASH. Examine the other keys to find their appropriate names.

So in a nutshell:

  • Our keyboard type is: 045e:00db
  • The scancode of the Slash key is: 70038
  • The name of the key for assigning is SLASH

After gathering the necessary information we create the configuration file:

sudoedit /etc/udev/hwdb.d/61-keyboard-local.hwdb

Hit i to activate the Insert mode and type the following:

keyboard:usb:v045Ep00DB*
 KEYBOARD_KEY_70038=minus      

Save and exit by pressing escape then typing :wq and hit enter.

Then run the following two commands for the configuration to take effect:

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

Finally unplug the keyboard and re-plug it in.

Some notes about the configuration file:

  • The format of the file should be exactly as shown, the space before mapping records is critical.
  • Instead of sudoedit you can use any other text editor, just remember to follow the exact format of the file as explained above.
  • There are two characters added to the keyboard type: v and p which stand for vendor and product. They are important as well.
  • The keyboard type is written uppercase in the configuration file. Our keyboard type was 045e:00db but in the configuration we insert v045Ep00DB*
  • The scancode of the key comes right after KEYBOARD_KEY_
  • The key name appears in lowercase in configuration file
  • You can customize pretty much every key on your keyboard following this tutorial.