Enabling Scroll with Microsoft Natural Ergonomic Keyboard 4000 in Ubuntu Linux

I recently purchased a new keyboard: Microsoft Natural Ergonomic Keyboard 4000. This has the split keyboard with a Zoom scroller in the middle, as well as various other extra buttons. All the keys worked by default in Ubuntu Natty - except the Zoom button. Rather than using it as zoom, I'd like to use it to scroll, as the scroll wheel on the mouse does. To get this working I followed the instructions given by Mauricio Faria de Oliveira.

Update (2011-09-25): There are some useful comments at the end of this post, giving clarity and improvements on my instructions (unfortunately my spam filter was mis-configured and I only just noticed the comments). I've retried my instructions on a new Ubuntu 11.04 install - they still work - and posted the complete set of commands and output, with improved line wrapping and highlighting. If you want an explanation of the steps then read on below. If you just want to see the commands I used then see the complete set.

Update (2011-12-30): There were several comments/questions about making it the scroller work after rebooting. After trying different approaches, Paul came up with the solution. I've applied his solution and added the steps to the end of this howto. And as an added bonus Paul also found the solution for mapping the buttons on the Microsoft Wireless Natural Mouse 6000 to different commands - check out his thread on Ubuntu Forums.

The problem is that the Zoom button by the keyboard produces keycodes (418, 419) higher than X11 supports (255). Hence the software EvRouter is used to handle this special case: whenever such a keycode is received from the keyboard, map it to an action that X11 can understand (i.e. the action for pressing moving the scroll wheel on the mouse up/down). To get continuous scrolling while holding the Zoom button in one position, Mauricio has created patch for evrouter that allows for repeat key presses.

Below are the detailed steps I performed, based mainly on the instructions and comments on Mauricio's blog as well as some hints for re-configuring using Automake, to get the Zoom button working as a scroller. I performed it on a new install of Ubuntu Natty 11.04.

Download EvRouter v0.4 source code and patch provided by Mauricio.

Several packages are needed to compile EvRouter. Install them:

$ sudo apt-get install automake libtool libX11-dev libxtst-dev

Assuming you are in the directory where the EvRouter source code and patch are located, unpack them both and apply the patch (note that the patch downloaded as a .tar.gz file with rather long random name):

$ tar xzf evrouter_0.4.tar.gz 
$ tar xzf gist754395-1ddb698f1bd8b762416fafba17431f3a2b8ebc60.tar.gz 
$ mv gist754395-1ddb698f1bd8b762416fafba17431f3a2b8ebc60/evrouter-0.4_with_key_repeats_option.patch \
evrouter-0.4/
$ cd evrouter-0.4
$ patch -p1 < evrouter-0.4_with_key_repeats_option.patch 
patching file src/action_xbutton.c
patching file src/cmdline.c
patching file src/cmdline.h

The current version of EvRouter is configured to use Automake v1.10, but v1.11 is installed. So before compiling EvRouter we need to update the references to v1.11 and re-configure:

$ rm compile 
$ ln -s /usr/share/automake-1.11/compile 

Open the configure with a text editor (e.g. nano, gedit) and on line 2333 change the version of Automake in the am__api_version variable from 1.10 to 1.11.

Now re-configure, compile and install:

$ aclocal
acinclude.m4:9: warning: underquoted definition of jm_CHECK_TYPE_STRUCT_UTIMBUF
acinclude.m4:9:   run info '(automake)Extending aclocal'
acinclude.m4:9:   or see http://sources.redhat.com/automake/automake.html#Extending-aclocal
$ libtoolize --force
libtoolize: putting auxiliary files in `.'.
...
libtoolize: Consider adding `-I m4' to ACLOCAL_AMFLAGS in Makefile.am.
$ autoconf
$ autoheader
$ automake --add-missing
configure.ac:23: installing `./config.guess'
configure.ac:23: installing `./config.sub'
$ ./configure
checking build system type... x86_64-unknown-linux-gnu
...
config.status: executing depfiles commands
$ make
make  all-recursive
...
make[1]: Leaving directory `/home/sgordon/Downloads/evrouter-0.4'
$ sudo make install
Making install in src
...
make[1]: Leaving directory `/home/sgordon/Downloads/evrouter-0.4'

EvRouter should now be installed and ready to run. It reads the file .evrouterrc in your home directory upon startup. So lets create this file and put the rules needed to map the event produced by the keyboard to the click of an button in X11. Go to your home directory and open .evrouterrc in a text editor and add the following lines (note that I've used the character "\" to wrap lines below; you should NOT use. The file should contain just two lines):

"Microsoft Natural® Ergonomic Keyboard 4000" \
"/dev/input/by-id/usb-Microsoft_Natural®_Ergonomic_Keyboard_4000-event-kbd" none key/418 "XButton/4"
"Microsoft Natural® Ergonomic Keyboard 4000" \
"/dev/input/by-id/usb-Microsoft_Natural®_Ergonomic_Keyboard_4000-event-kbd" none key/419 "XButton/5"

The rules match a device (the keyboard) and some event produced by the device (key press identified by number 418) and map it into an event that X11 can understand. In this case the press of XButton/4, i.e. the up movement on the mouse scroll wheel.

To access the keyboard device using EvRouter, the normal user (you) needs permissions (replace sgordon with your username):

$ sudo chown sgordon /dev/input/by-id/usb-Microsoft_Natural®_Ergonomic_Keyboard_4000-event-kbd

Now test that everything works by running EvRouter in debug mode (-d option):

$ evrouter -d /dev/input/by-id/usb-Microsoft_Natural®_Ergonomic_Keyboard_4000-event-kbd
device  0: /dev/input/by-id/usb-Microsoft_Natural®_Ergonomic_Keyboard_4000-event-kbd: \
Microsoft Natural® Ergonomic Keyboard 4000
Display name: :0.0

Moving the keyboard zoom key up should produce something similar to:

Window "(null)": # Window title
# Window "(null)": # Resource name
# Window "(null)": # Class name
"Microsoft Natural® Ergonomic Keyboard 4000" \
"/dev/input/by-id/usb-Microsoft_Natural®_Ergonomic_Keyboard_4000-event-kbd" \
none key/418 "fill this in!"

And down:

Window "(null)": # Window title
# Window "(null)": # Resource name
# Window "(null)": # Class name
"Microsoft Natural® Ergonomic Keyboard 4000" \
"/dev/input/by-id/usb-Microsoft_Natural®_Ergonomic_Keyboard_4000-event-kbd" \
none key/419 "fill this in!"

Update: If this doesn't work, then try another id of the Zoom button event. In the directory /dev/input/by-id/ I have two Microsoft keyboard entries: the one above and one with if01 also in the name. Retry with this other name, setting the ownership (chown), editing .evrouterrc amd the command line above and below.

Now run EvRouter, this timing using the -r option to allow for repeat keys so that you can hold the Zoom button and get continuous scrolling (this option is what the patch provided).

$ sudo evrouter -r /dev/input/by-id/usb-Microsoft_Natural®_Ergonomic_Keyboard_4000-event-kbd
device  0: /dev/input/by-id/usb-Microsoft_Natural®_Ergonomic_Keyboard_4000-event-kbd: \
 Microsoft Natural® Ergonomic Keyboard 4000
Display name: :0.0
Parsed 2 rules, 144 bytes

EvRouter is now running (as a daemon in the background). Use the zoom button to test it in a browser or terminal.

If you want to change the actions the Zoom button performs (instead of scrolling), then replace the XButton/4 and XButton/5 in the .evrouterrc file to the actions you want. For example, for keyboard keys, use XKey/code, where code is the name found in parenthesis in the output of:

$ xmodmap -pk 

Read the man page for EvRouter for more info about the rules, including how to match the action to specific windows (i.e. perform different actions in Firefox and Terminal).

Finally, lets make the scroller automatically work after a reboot. The last sudo evrouter -r ... command above needs to be run upon boot (more precisely, after X starts). Thanks to the comments by Paul the steps are to first allow your user to run evrouter as sudo without prompting for a password and then add the evrouter command to the list of startup applications.

The following allows a user (in this case, sgordon - change to your username) to execute the evrouter program without prompting for the sudo password.

sgordon ALL = NOPASSWD: /usr/local/bin/evrouter

It needs to be added to the /etc/sudoers file, or as I did it, to its own file, such as evrouter, in the /etc/sudoers.d/ directory (you can use the directory approach if the directory /etc/sudoers.d/ already exists, otherwise add the line to the end of the /etc/sudoers file using visudo). Below is the output after I created and edited the file /etc/sudoers.d/evrouter:

$ cd /etc/sudoers.d/
$ ls
evrouter  README
$ sudo cat evrouter 
sgordon ALL = NOPASSWD: /usr/local/bin/evrouter

Now when you execute evrouter with sudo privileges you will NOT be prompted for a password. Try it in a new terminal to check that it works.

Next add the sudo evrouter -r ... command to the Startup Applications. Call it what you like. Below is a screenshot after I've added it:

Be careful with the quotes. Its not shown in the above image but the exact command is:

sudo evrouter -r '/dev/input/by-id/usb-Microsoft_Natural®_Ergonomic_Keyboard_4000-if01-event-kbd'

Now reboot and if all's well scrolling should work automatically!

Content: 

Comments

Hello Steve.

Thanks for the feedback on that post
and the links for my personal blog.

I'm glad to know that it was useful to you :-)

Best regards!

Thanks a lot! I just got one of these keyboards today, and I spent a while trying to figure out how to handle the zoom slider before I came across this. Exactly what I was looking for.

I am pretty new with Linux, but with your help I got the slider working! Thank you very much!

But, when I wanted to use it as zoom, I could not do that... I replaced the "XButton/4" and "XButton/5" with "Zoom + action" and "Zoom - action" as it says in a couple of pages I googled, but it gives this:

stdin:1: action type "zoom + action" is unrecognised.

What could be the right parameters? (I am using the if01-file.)

Btw, when running the evrouter, is this line one complete command:

evrouter -r /dev/input/by-id/usb-Microsoft_Natural®_Ergonomic_Keyboard_4000-event-kbd
device 0: /dev/input/by-id/usb-Microsoft_Natural®_Ergonomic_Keyboard_4000-event-kbd: \
Microsoft Natural® Ergonomic Keyboard 4000

?
Pretty confused with the line breaks and the "\" in between.

Hi Steve and Mauricio,

Thanks for this wonderful walkthrough! This article is one of the reasons that made me buy this keynoard.

It works perfectly, although I had to make some modifications to make it work for my Wireless "Microsoft Natural Ergonomic Desktop 7000" (same keyboard layout, but combined with a mouse and wireless.

For everyone interested, here are the changes I had to make:

  • Another zoom button event id had to be used:
    • Not: "/dev/input/by-id/usb-Microsoft_Natural®_Ergonomic_Keyboard_4000-event-kbd"
    • But: "/dev/input/by-id/usb-Microsoft_Microsoft®_2.4GHz_Transceiver_V1.0-event-mouse"
  • Device name had to be changed:
    • Not: "Microsoft Natural® Ergonomic Keyboard 4000"
    • But: "Microsoft Microsoft® 2.4GHz Transceiver V1.0"
  • Also I had problems because I had originally saved the file ".evrouterrc" in a non-unicode encoding (latin1 i believe). After saving in UTF8, it worked.

Best regards, Bart

Perfect solution, thanks.
I failed to configure it natively on os x but it works on mac when the keyboard is connected to linux machine with synergy.

Thanks for these detailed instructions. They worked perfectly. You turned a task that would have taken a couple of hours into a 15 minute one. Thanks again.

Hi Steve,

Sunny here, happened to be your TA a long time ago. Where did you buy it from? Have been looking all over Bangkok and it seems out of stock.

Here is another approach to compile EvRouter which is a bit shorter (Tested un Ubuntu 10.4):

The first steps are the the same:


$ tar xzf evrouter_0.4.tar.gz
$ tar xzf gist754395-1ddb698f1bd8b762416fafba17431f3a2b8ebc60.tar.gz
$ mv gist754395-1ddb698f1bd8b762416fafba17431f3a2b8ebc60/evrouter-0.4_with_key_repeats_option.patch \
evrouter-0.4/
$ cd evrouter-0.4
$ patch -p1 < evrouter-0.4_with_key_repeats_option.patch

I tried the following steps with editing the configure script but got the error message:

configure: error: cannot run /bin/bash ./config.sub

After a short search I found out that executing the script

./autogen.sh

will do all changes to the new autotools version without the need of changing the symlink or other stuff.

Compiling and installing and running the debug test worked like a charm

But when I tried to run EvRouter with the -r option I get the following error message:


$ evrouter -r /dev/input/by-id/usb-Microsoft_Natural®_Ergonomic_Keyboard_4000-event-kbd
device 0: /dev/input/by-id/usb-Microsoft_Natural®_Ergonomic_Keyboard_4000-event-kbd: Microsoft Natural® Ergonomic Keyboard 4000
Display name: :0.0
stdin:1: Syntax error (Expected 'Window' or a string)

I tried it with installations compiled with my and your method.
Any hints?

Andreas

Hi Sunny,
Got mine in IT City at Zeer Rangsit for B1750. It was out of stock in JIB and didn't see it in many other shops. I guess IT City in other places (e.g. Pantip) may also have it or be able to get it. Note that it only has English keys, not Thai. Not sure if there is a Thai version.
Steve

Sorry about the confusion with the line breaks. I manually inserted the \ characters so that the web page would not be too wide. Yes, they mean line break.

For input, if you see a \ you don't need to type, just continue typing the next line (without hitting enter). Alternatively, you can type the \ when working on the command line which will allow you to continue the command.

For output, just ignore the \ in my posts.
Steve

Thanks very much for this. This is possibly the clearest How To I have ever read. Exactly what I needed.

You need to run the 'evrouter -r ...' command upon boot to get the scrolling working. Try putting the command in a startup or login script. E.g. add it to the file /etc/rc.local or your .bashrc startup script in your home directory.

Steve, I was unable to find proper up-to-date guide to configuring mouse buttons for Microsoft Wireless Natural Mouse 6000 which is often used with this keyboard, so I had to figure out things myself with the help of some crafty folks from the Ubuntu Community, which I did successfully.

This resulted in this how-to: http://ubuntuforums.org/showthread.php?p=11574067

Please attach the link to the post, so people with similar hardware configuration may benefit.

Thank you Steve, for things like this and people like you supporting GNU/Linux is why I changed OS, things like this make own system better and tutos like this make the community bigger and supported

One of the issues that Linux users have to deal with is sometimes things just don't work the same way (as things are not designed with Linux in mind.)

So it's a great benefit to other users when more technical people like you find and post little fixes like this.

This article is exactly what I was looking for to get my "zoom" key working.