# Logitech Multimedia Keyboard and Mouse Combo Tutorial

## psychomunky

A'ight, co-forum member Dralnu and I have been having a little bit o' trouble getting our Logitech MX3000 keyboard/Mouse combos working in X windows.  Right now focus has been on the keyboard, so let me start there.  This first post I will attempt to keep up-to-date as a tutorial for others.  Once things have stablized, I will move it over to http://www.Gentoo-Wiki.com.

Information about the MX3000 Cordless Desktop Combo

After looking at Logitech's website, I found the following out about the MX3000 combo that may prove useful:

 The keyboard model is MX3000

 The mouse is actually an MX600

 If you choose to use PS/2 then both keyboard and mouse need to be PS/2.  Unfortunately, at the moment, PS/2 is the only way to get all keys on the keyboard working.  It seems, however, that using USB allows you to get all mouse buttons working (something I have yet to accomplish in PS/2 mode).  Since there are only 3 mouse buttons, I haven't been able to get working in PS/2 mode (zoom-, zoom+ and 100%) and those buttons are duplicated on the keyboard, I have chosen to go the PS/2 route and sacrifice the 3 mouse buttons that don't work for now, instead of the 20+ keyboard buttons that aren't recognized in USB mode.

Pre-requisites

First, there are a few issues that we work around:

 The current USB keyboard driver in the current series of the Linux kernel (2.6.*) is somewhat broken.  This will stop us from getting all of the keyboard keys working.  Please shut down your machine and switch your keyboard and mouse over to PS/2.  This sucks much, but the author of keytouch is working with the kernel devs to rectify this.

 I initially had trouble after switching to PS/2 with my mouse not working.  The problem was I hadn't enabled proper support for all of the serio stuff. I needed to enable ISA support (my PS/2 ports apparently use an ISA bus),  and Plug and Play support.

Section 1: The Keyboard

Getting the keyboard to work the easy way (using Keytouch)

This section of the tutorial will use the keytouch software (http://keytouch.sf.net) to get things up and running.  Keytouch has the following advantages that make it a good choice to get up and running quickly:

 It is built with GTK+ and has support for KDE (if you enable the kde use flag), so most users that use the 2 main desktops should not have to pull in large amounts of dependencies (I use KDE and already had the bear minimum of GTK installedfor a few other apps I use).

 It comes with a very user friendly interface that is easy to navigate and set up.

 There are quite a few built-in plugins that work with the most popular applications, so there is little need for shell scripting/additional programming.

 Most of the default keyboard profiles come with really sane default actions, so you can be up and running in minimal time.

The steps to follow are:

 The first step is to get the keytouch software.  It is likely masked (it definately is for x86), so do the following after you have updated your portage tree:

```

$ echo "x11-misc/keytouch ~x86" >> /etc/portage/package.keywords

$ emerge -av keytouch

```

 The first thing to do is make certain the keytouvh daemon is running.  As root:

```
$ /etc/init.d/keytouch start
```

You probably want this to happen automatically at startup, so add it to your default runlevel (again as root):

```
$ rc-update add keytouch default
```

 Next, we need to setup a profile file for Keytouch to use.  So open your favorite text-editor and copy and paste the following into a file called MX3000.Logitech (it does not matter where this file is located).

```
<keyboard>

  <file-info>

    <syntax-version>1.1</syntax-version>

    <last-change format="%d-%m-%Y">15-12-2006</last-change>

    <author>Chris Roe</author>

  </file-info>

  <keyboard-info>

    <keyboard-name>

      <manufacturer>Logitech</manufacturer>

      <model>MX3000</model>

    </keyboard-name>

  </keyboard-info>

  <key-list>

    <key>

      <name>Back</name>

      <scancode>234</scancode>

      <keycode>BACK</keycode>

      <default-action action-type="plugin">

        <plugin-name>WWW Browser</plugin-name>

        <plugin-function>Back</plugin-function>

      </default-action>

    </key>

    <key>

      <name>Close All</name>

      <scancode>109</scancode>

      <keycode>CLOSE</keycode>

      <default-action action-type="plugin">

        <plugin-name>Common actions</plugin-name>

        <plugin-function>Close/Quit</plugin-function>

      </default-action>

    </key>

    <key>

      <name>Scroll Down button</name>

      <scancode>130</scancode>

      <keycode>SCROLLDOWN</keycode>

      <default-action action-type="plugin">

        <plugin-name>Scroll</plugin-name>

        <plugin-function>Down</plugin-function>

      </default-action>

    </key>

    <key>

      <name>Scroll Up Button</name>

      <scancode>131</scancode>

      <keycode>SCROLLUP</keycode>

      <default-action action-type="plugin">

        <plugin-name>Scroll</plugin-name>

        <plugin-function>Down</plugin-function>

      </default-action>

    </key>

    <key>

      <name>Zoom-</name>

      <scancode>132</scancode>

      <keycode>BRIGHTNESSDOWN</keycode>

      <default-action action-type="plugin">

        <plugin-name>Zoom</plugin-name>

        <plugin-function>Out</plugin-function>

      </default-action>

    </key>

    <key>

      <name>Zoom+</name>

      <scancode>106</scancode>

      <keycode>BRIGHTNESSUP</keycode>

      <default-action action-type="plugin">

        <plugin-name>Zoom</plugin-name>

        <plugin-function>In</plugin-function>

      </default-action>

    </key>

    <key>

      <name>100%</name>

      <scancode>107</scancode>

      <keycode>WWW</keycode>

      <default-action action-type="plugin">

        <plugin-name>Zoom</plugin-name>

        <plugin-function>100%</plugin-function>

      </default-action>

    </key>

    <key>

      <name>Movies</name>

      <scancode>148</scancode>

      <keycode>KBDILLUMDOWN</keycode>

      <default-action action-type="plugin">

        <plugin-name>Filemanager</plugin-name>

        <plugin-function>Documents</plugin-function>

      </default-action>

    </key>

    <key>

      <name>Music</name>

      <scancode>147</scancode>

      <keycode>KBDILLUMTOGGLE</keycode>

      <default-action action-type="plugin">

        <plugin-name>Filemanager</plugin-name>

        <plugin-function>Documents</plugin-function>

      </default-action>

    </key>

    <key>

      <name>Pictures</name>

      <scancode>149</scancode>

      <keycode>KBDILLUMUP</keycode>

      <default-action action-type="plugin">

        <plugin-name>Filemanager</plugin-name>

        <plugin-function>Documents</plugin-function>

      </default-action>

    </key>

    <key>

      <name>My Documents</name>

      <scancode>213</scancode>

      <keycode>MACRO</keycode>

      <default-action action-type="plugin">

        <plugin-name>Filemanager</plugin-name>

        <plugin-function>Documents</plugin-function>

      </default-action>

    </key>

    <key>

      <name>BurnCD</name>

      <scancode>177</scancode>

      <keycode>MSDOS</keycode>

      <default-action>k3b || gnomebaker</default-action>

    </key>

    <key>

      <name>Record</name>

      <scancode>248</scancode>

      <keycode>RECORD</keycode>

      <default-action>krec || gnome-sound-recorder</default-action>

    </key>

    <key>

      <name>Media</name>

      <scancode>237</scancode>

      <keycode>MEDIA</keycode>

      <default-action>vlc || kmplayer || gmplayer</default-action>

    </key>

    <key>

      <name>Shuffle</name>

      <scancode>114</scancode>

      <keycode>SPORT</keycode>

      <default-action>dcop amarok playlistbrowser loadPlaylist &quot;Random Mix&quot;</default-action>

    </key>

    <key>

      <name>Mute</name>

      <scancode>160</scancode>

      <keycode>MUTE</keycode>

      <default-action action-type="plugin">

        <plugin-name>Amixer</plugin-name>

        <plugin-function>Mute</plugin-function>

      </default-action>

    </key>

    <key>

      <name>Previous song</name>

      <scancode>144</scancode>

      <keycode>PREVIOUSSONG</keycode>

      <default-action action-type="plugin">

        <plugin-name>Amarok</plugin-name>

        <plugin-function>Previous</plugin-function>

      </default-action>

    </key>

    <key>

      <name>Next song</name>

      <scancode>153</scancode>

      <keycode>NEXTSONG</keycode>

      <default-action action-type="plugin">

        <plugin-name>Amarok</plugin-name>

        <plugin-function>Next</plugin-function>

      </default-action>

    </key>

    <key>

      <name>Volume Up</name>

      <scancode>176</scancode>

      <keycode>VOLUMEUP</keycode>

      <default-action action-type="plugin">

        <plugin-name>Amixer</plugin-name>

        <plugin-function>Volume increase</plugin-function>

      </default-action>

    </key>

    <key>

      <name>Volume Down</name>

      <scancode>174</scancode>

      <keycode>VOLUMEDOWN</keycode>

      <default-action action-type="plugin">

        <plugin-name>Amixer</plugin-name>

        <plugin-function>Volume decrease</plugin-function>

      </default-action>

    </key>

    <key>

      <name>Playlist-</name>

      <scancode>242</scancode>

      <keycode>HANJA</keycode>

      <default-action action-type="plugin">

        <plugin-name>KDE Switch Desktop</plugin-name>

        <plugin-function>Previous Desktop</plugin-function>

      </default-action>

    </key>

    <key>

      <name>Playlist+</name>

      <scancode>243</scancode>

      <keycode>HANGUEL</keycode>

      <default-action action-type="plugin">

        <plugin-name>KDE Switch Desktop</plugin-name>

        <plugin-function>Next Desktop</plugin-function>

      </default-action>

    </key>

    <key>

      <name>Preset1</name>

      <scancode>172</scancode>

      <keycode>PROG1</keycode>

      <default-action></default-action>

    </key>

    <key>

      <name>Preset2</name>

      <scancode>165</scancode>

      <keycode>PROG2</keycode>

      <default-action></default-action>

    </key>

    <key>

      <name>Preset3</name>

      <scancode>166</scancode>

      <keycode>PROG3</keycode>

      <default-action></default-action>

    </key>

    <key>

      <name>Eject</name>

      <scancode>175</scancode>

      <keycode>EJECTCLOSECD</keycode>

      <default-action>eject -T</default-action>

    </key>

    <key>

      <name>Play/Pause</name>

      <scancode>162</scancode>

      <keycode>PLAYPAUSE</keycode>

      <default-action action-type="plugin">

        <plugin-name>Amarok</plugin-name>

        <plugin-function>Play/Pause</plugin-function>

      </default-action>

    </key>

    <key>

      <name>Stop CD</name>

      <scancode>164</scancode>

      <keycode>STOP</keycode>

      <default-action action-type="plugin">

        <plugin-name>Amarok</plugin-name>

        <plugin-function>Stop</plugin-function>

      </default-action>

    </key>

    <key>

      <name>Mail</name>

      <scancode>236</scancode>

      <keycode>MAIL</keycode>

      <default-action action-type="plugin">

        <plugin-name>E-mail</plugin-name>

        <plugin-function>E-mail</plugin-function>

      </default-action>

    </key>

    <key>

      <name>Messenger</name>

      <scancode>145</scancode>

      <keycode>QUESTION</keycode>

      <default-action>dcop kopete mainWindow setHidden &quot;`dcop kopete mainWindow shown`&quot; || kopete || gaim</default-action>

    </key>

    <key>

      <name>Status</name>

      <scancode>245</scancode>

      <keycode>YEN</keycode>

      <default-action>echo -e &quot;Uptime: `uptime`\nO/S: `uname -o`\nKernel: `uname -r`\nProcessor: `uname -p`&quot; | osd_cat</default-action>

    </key>

    <key>

      <name>Webcam</name>

      <scancode>244</scancode>

      <keycode>CAMERA</keycode>

      <default-action></default-action>

    </key>

    <key>

      <name>Sleep</name>

      <scancode>223</scancode>

      <keycode>SLEEP</keycode>

      <default-action action-type="plugin">

        <plugin-name>Lock Screen</plugin-name>

        <plugin-function>Lock Screen</plugin-function>

      </default-action>

    </key>

    <key>

      <name>Calculator</name>

      <scancode>161</scancode>

      <keycode>CALC</keycode>

      <default-action>(dcop `dcop | grep &apos;kcalc&apos; | head -n 1` kcalc-mainwindow#1 hide &amp;&amp; dcop `dcop | grep &apos;kcalc&apos; | head -n 1` kcalc-mainwindow#1 show) || kcalc || gnome-calculator || xcalc</default-action>

    </key>

    <key>

      <name>FMode-Battery</name>

      <scancode>187</scancode>

      <keycode>PROG4</keycode>

      <default-action></default-action>

    </key>

    <key>

      <name>FMode-WordProcessor</name>

      <scancode>188</scancode>

      <keycode>CONNECT</keycode>

      <default-action>oowriter2 || kword || abiword || kate || kwrite || gedit</default-action>

    </key>

    <key>

      <name>FMode-Spreadsheet</name>

      <scancode>189</scancode>

      <keycode>ALTERASE</keycode>

      <default-action>oocalc2 || kspread || gnumeric</default-action>

    </key>

    <key>

      <name>FMode-Presentations</name>

      <scancode>190</scancode>

      <keycode>COFFEE</keycode>

      <default-action>ooimpress2 || kpresenter || criawips</default-action>

    </key>

    <key>

      <name>FMode-Undo</name>

      <scancode>191</scancode>

      <keycode>UNDO</keycode>

      <default-action action-type="plugin">

        <plugin-name>Common actions</plugin-name>

        <plugin-function>Undo</plugin-function>

      </default-action>

    </key>

    <key>

      <name>FMode-Redo</name>

      <scancode>192</scancode>

      <keycode>REDO</keycode>

      <default-action action-type="plugin">

        <plugin-name>Common actions</plugin-name>

        <plugin-function>Redo</plugin-function>

      </default-action>

    </key>

    <key>

      <name>FMode-Print</name>

      <scancode>193</scancode>

      <keycode>PRINT</keycode>

      <default-action action-type="plugin">

        <plugin-name>Common actions</plugin-name>

        <plugin-function>Print</plugin-function>

      </default-action>

    </key>

    <key>

      <name>FMode-Save</name>

      <scancode>194</scancode>

      <keycode>SAVE</keycode>

      <default-action action-type="plugin">

        <plugin-name>Common actions</plugin-name>

        <plugin-function>Save</plugin-function>

      </default-action>

    </key>

    <key>

      <name>FMode-a</name>

      <scancode>195</scancode>

      <keycode>SWITCHVIDEOMODE</keycode>

      <default-action></default-action>

    </key>

    <key>

      <name>FMode-b</name>

      <scancode>196</scancode>

      <keycode>WAKEUP</keycode>

      <default-action></default-action>

    </key>

    <key>

      <name>FMode-c</name>

      <scancode>215</scancode>

      <keycode>SUSPEND</keycode>

      <default-action></default-action>

    </key>

    <key>

      <name>FMode-d</name>

      <scancode>216</scancode>

      <keycode>SHOP</keycode>

      <default-action></default-action>

    </key>

  </key-list>

</keyboard>

```

 Now run the keytouch software as a normal user:

```
$ keytouch
```

You will be warned that you have not chosen a keyboard.  Click the ok button and enter the root password on the next dialog to choose a keyboard.

 The dialog box you are now looking at has a list of keyboards that you can just double-click on to choose you keyboard.  Unfortunately, the Logitech MX3000 is not listed there.  Click the "Import..." button.  Choose the file that you created 2 steps ago.

 Now you can scroll down in the keyboard models list to the Logitech section and pick the MX3000.  Press OK.

 You will have now returned to the main key touch interface, with a list of all of the extra keys on the MX3000 on the left and their actions on the right.  I have tried to give reasonable defaults to most keys, but some keys (such as the preset keys) seem to exist for pure customization.  For those keys, I have defined no default action.  Scroll through the list of keys and make certain they will execute what you wish them to.  There are a number of plugins available in keytouch that work with many programs.

 Click OK or Apply and test out your multimedia keys!!!

At this point, everything will work until you log out.  When you log in again, you will find that things may not be working as expected.  The reason for this is that keytouch requires a daemon to be running to intercept and translate the key presses.  You need to load this daemon on startup.  Under KDE, simply create a ~/.kde/Autostart/keytouchd.desktop file and put these contents into it:

```
[Desktop Entry]

Exec=keytouchd

Name=Keytouch Daemon

Type=Application

X-KDE-StartupNotify=false

```

For Gnome: Open "System > Preferences > Sessions" click on the "Startup Programs" tab, click "Add" and enter "keytouchd".

I would really appreciate feedback on the chosen defaults, keeping the following in mind:

 the keytouch developers prefer KDE over Gnome, which is why the KDE version of something is attempted in the defaults first.  Please refrain from "religious" desktop wars please.

 I myself am mainly a KDE user, and may have inadvertantly gotten some of the Gnome commands wrong.  Corrections and suggestions for better choices/omissions is definately welcome.

 Given the choice between a KDE based app, a Gnome based app, or a desktop neutral app, the neutral app gets preference, then KDE, then Gnome. (which is why the "Office" buttons attempt to load OpenOffice.org apps first).

 I am looking for sensible defaults for the profile posted above.  You are always able to customize your own mappings by running the keytouch application.  The profile mainly exists to tell keytouch what keys are available.  The ability to define default actions is a bonus to make usability that much better.

Getting the keyboard to work the next easiest way (lineakd)

This method is only slightly more difficult than that of using keytouch.  This only because you are generally going to have to edit configuration files by hand.  Lineakd has a few features that make it another good choice for using your extra keys:

 There are no dependencies beside standard X librarie required, so it should work with all desktops.

 There are quite a few built-in plugins that work with the most popular applications, so there is little need for shell scripting/additional programming.  Though, I find the built-in plugins are targetted more toward basic X applications, rather than Qt or GTK+ based ones.  This may be good, it may be bad...depends on your own preferences.

 Although more direct editing of configuration files is required, it is still relatively simple to get going.

At the moment I am going leave the rest of this section as a TODO.  I will return to it, once I have the mouse configuration figured out and working.

Configuring the keyboard the purist way (xbindkeys)

For the advanced user and the user that wishes to have the absolute most in flexibility in key configuration, xbindkeys is for you.  It relies only on the X server, has no plugins, and requires the user to write the complete configuration file.  However, since it is so tightly integrated with X, it does not rely on a daemon to be running like lineak does.

For the moment, The rest of this section will remain in TODO form.  I am going to attempt to get my mouse working, then lineakd, then I will come to xbindkeys.

Scancodes generated by the MX3000

I have translated the above keytouch config file into an easier to read image.  This image describes the scancodes generated by the linux kernel for the MX3000 keyboard when plugged into a PS/2 port (USB does not yet generate all of the necessary scancodes).

Ckick here for the image

Section 2: The Mouse

Part One: getting X.org to recognize all the buttons

The mouse that comes with the MX3000 kit, is actually an MX600 Laser mouse.  To get all buttons working that we currently can through PS/2, we are going to use the xorg evdev driver in our xorg.conf.

 Ensure your kernel has been built with event support.  Make sure the following options were enabled

```
Device Drivers --->

    Input Device Support --->

        <*> Event interface

```

 To make sure your mouse is recognized, do the following:

```
$ cat /proc/bus/input/devices
```

If you are using the MX 600 mouse plugged into PS/2 you should see the following:

```
I: Bus=0011 Vendor=0002 Product=0006 Version=007f

N: Name="ImExPS/2 Logitech Explorer Mouse"

P: Phys=isa0060/serio1/input0

S: Sysfs=/class/input/input2

H: Handlers=mouse0 event2

B: EV=7

B: KEY=1f0000 0 0 0 0 0 0 0 0

B: REL=143

```

If you have a different mouse, or you are running in USB mode, then you'll see something different.  Keep this output handy, we will need in a moment.

Next open your /etc/X11/xorg.conf file in your favorite editor:

```
$ nano -w /etc/X11/xorg.conf
```

 Comment our the current "InputDevice" section for your mouse and add a new one that looks like the following:

```
Section "InputDevice"

        Identifier "Mouse0"

        Driver "evdev"

        Option "Dev Name" "ImExPS/2 Logitech Explorer Mouse"

        Option "Device" "/dev/input/event2"

        Option "Buttons" "12"

#        Option "ButtonMapping" "1 2 3 8 9 4 5 6 7 10 11"

EndSection

```

Now you may need to make the following changes:

 Change the value of the "Dev Name" option to value of "N: Name=" line from the /proc output above.  This is case-sensitive, so a copy and paste is recommended.

 If you have a single mouse, the "Device" line is likely unnecessary. However, if your machine always assigns the same device to you mouse, you can add it and put the path to the device file here.

 If you have multiple mice (especially those with the same name), then you may want to add a "Dev Phys" option.  The value for this option will be a pattern matching the "P: Phys=" line of the proc output.  Example:

```
Option "Dev Phys" "isa*/serio1/input0"
```

 You may need to change the "Buttons" and "ButtonMappings" options to match your mouse.  The MX600 has 12 (2 standard butons, the press of the scroll wheel, rotating the scroll wheel (one for forward, one for backward), the 2 side buttons (cruise control, or hyper scroll buttons as they are sometimes called) and Zoom+, Zoom-, 100%).  Xorg detects 9 of these 12 buttons via PS/2 just fine, so there is no need for the "ButtonMappings" option.

 At this point, you can restart your X windows environment by logging out, then hitting [ctrl]-[alt]-[bcksp], restarting /etc/init.d/xdm or running startx again after logging out.  Which method you choose depends upon your method of starting X in the firstplace.

 You should now have a completely working mouse.  To test this, open a console within X and run the following:

```
$ xev
```

This will pop-up a small white window.  Click to focus it and then carefully (without moving the mouse), press each one of your mouse buttons. Each button press will generate something similar to the following in the console:

```
ButtonPress event, serial 28, synthetic NO, window 0x3600001,

    root 0x168, subw 0x0, time 2449591881, (161,6), root:(165,31),

    state 0x0, button 1, same_screen YES

ButtonRelease event, serial 28, synthetic NO, window 0x3600001,

    root 0x168, subw 0x0, time 2449592081, (161,6), root:(165,31),

    state 0x100, button 1, same_screen YES

```

All of the buttons except, the 3 Zoom buttons should work.  At this point you probably want to note which each button is (read the output from the ButtonPress and ButtonRelease events, it tells you the button pressed, in the example it was button 1).  My MX600 generated the following button numbers:

 Left mouse - button 1

 Clicking the Scroll button - button 2

 Right mouse button - button 3

 Scroll button forwards - button 4

 Scroll backwards - button 5

 Tilt Scroll Button left - button 6

 Tilt Scroll button right - button 7

 Rear side button - button 8

 Front side button - button 9

 At this point some applications will already recognize more than the standard non-tilt scroll-wheel mouse button.  For example, Firefox uses buttons 6 and 7 to move forward and back(respectively) through your history.  Experiment with your buttons in different apps and see aht they do.

Part Two (optional): Remapping your mouse buttons

If you are like me and don't like the default assignments for your mouse buttons, then you can tell X to remap them by executing the xmodmap command:

```
$ xmodmap -e "pointer = 1 2 3 4 5 6 7 8 9 10 11 12"
```

Now this command is not very useful, because it will result in the same mouse button mapping that X.org originally came up with.  Now I now that X detect my buttons in the following order: left, middle, right, scroll forward, scroll back, left tilt, right tilt, rear side button, front side button.  This is the order that the button numbers from the xmodmap command will be assigned to your mouse.

If your PC complains it can't find xmodmap, you need to emerge it:

```
$ emerge -av xmodmap
```

Since I know that Firefox uses buttons 6 and 7 for forward and backward history navigation, and that I'd prefer the left tilt to go back in the history and the right tilt to go forward, I issue the following command:

```
xmodmap -e "pointer = 1 2 3 4 5 7 6 8 9 10 11 12"
```

Note the transposing of the 6 and 7 from the original command above.

After using my mouse this way, a found I really didn't like the tilts to move me back and forth through the history.  Instead I wanted the side buttons to do it, with the front button going forward, and the rear button moving backwards through the history.  That was solved via the following command:

```
xmodmap -e "pointer = 1 2 3 4 5 8 9 7 6 10 11 12"
```

Note that the 8 and 7 replaced each other as did 6 and 9.

Unfortunately, these re-mappings only last for your X session, so as soon as you log out, they are lost.  Fortunately, you can persist them once you find settings you like.  Just add the contents of the quotes in your preferred xmodmap command to ~/.Xmodmap.  Create this file if you need to, and replace any existing "pointer = " line in the file.

Now run:

```
$ xmodmap ~/.Xmodmap
```

to make the settings active. When you re-login to X then your mouse buttons should be setup the way you like them.

NOTE TO KDM/KDE Users and GDM/Gnome Users: According to this wiki page, your xinitrc may not be respected by these two desktops.  Have a look at the wiki page for work arounds for your desktop.

Part three (optional): Getting extra button to do wacky and useful things

By far, one of the biggest advantages of having a mouse with so many buttons is that you can bind actions to the buttons you don't regularly use.  This section discusses how you can map actions to the mouse buttons.  These actions all run a command, as you would in the console.  However, with a few X utilities we can also send key strokes  and other keyboard events.  As well, you can create your own scripts and have them invoked by you mouse buttons.  This whole process may seem a bit familiar, as it is very similar to using xbindkeys to bind actions to your keyboard keys.

Many applications seem not to work out of the box with the tilt action of the scroll wheel on the MX600.  Normally the tilt actions should scroll left and right, but either don't, or have completely different behaviour.  This is relatively easy to fix, but we need to ensure we have a few pieces of X.org before we can get this to work.

```
$ emerge -av xbindkeys xvkbd
```

xbindkeys is what allows us to bind actions to a mouse button.  xvkbd allows us to generate key press events in X.

Next we need to know what buttons we are mapping actions to,  In this case, it is 6 (tilt toward the thumb) and 7 (tilt away from the thumb).  If you re-mapped your buttons, use xev to see which buttons you need to map to.

Finally, we map the buttons to actions.  This is done using the ~/.xbindkeysrc file (create it if you don't have it). Then open it in you favorite editor.

Enter something at the end of this file in the form of:

```
"<command>"

  m:0x0 + b:<button number>

```

Where <command> specifies the command to execute when this button is pressed and <button number> is the number of the button that you want to map to as returned by xev.

For our example of getting the left and right tilts working to scroll left and right in most applications, we are simply going to ask them to send a left and right key press respectively (this is where xvkbd comes in...read its man page for more info), so we add the following to the bottom of the ~/.xbindkeys file:

```
"/usr/X11R6/bin/xvkbd -xsendevent -text "\[Left]""

  m:0x0 + b:6

"/usr/X11R6/bin/xvkbd -xsendevent -text "\[Right]""

  m:0x0 + b:7

```

Note that the Right and Left portions of the command are case-sensitive.

Save the file and run the following to make it take effect right away:

```
$ xbindkeys
```

 Finally you need to make certain that xbindkeys is run when you start your X session. If you have a desktop that respect xinitrc, then hopefully everything will work.  If you are running KDE or Gnome, you will have no such luck.  In KDE, create a file called ~/.kde/Autostart/xbindkeys.desktop with the following contents:

```
[Desktop Entry]

Exec=xbindkeys

Name=Load Key Mappings for X

Type=Application

X-KDE-StartupNotify=false

```

For Gnome: Open "System > Preferences > Sessions" click on the "Startup Programs" tab, click "Add" and enter "xbindkeys".

TODO

The following things I will be adding to this post over the next little while:

 How to get all 12 "buttons" on the mouse recognized by X windows (9 of them completed)

 Mapping actions to the "special" buttons on the mouse.

 After a period of time for suggestions and improvements, I'll submit the profile above to the keytouch dev.

Credits

The responders below - For their suggestions

 http://gentoo-wiki.com/HOWTO_Advanced_Mouse - Helped with figuring out how to get the mouse buttons working (as a reward to that tutorial I put the xorg.conf and xmodmap settings into the specific mouse configurations).

 http://ubuntuforums.org/showthread.php?t=65471 - Helped with getting the re-mapping working (xmodmap stuff) and binding actions to buttons.

Last edited by psychomunky on Mon Dec 18, 2006 9:09 pm; edited 12 times in total

----------

## stahlsau

hi,

nice howto.

Few ideas from myself: why not using xbindkeys? Most people have got that installed for their multimedia-buttons on the keyboard already, and it doesn't have a that cryptic configuration file (did i say that i hate xml already?  :Wink: ).

My xbindkeysrc looks like this:

```
"mpc toggle && /home/xxx/scripts/play"

c:162

"mpc stop && /home/xxx/scripts/stop"

c:164

"mpc next && /home/xxx/scripts/next"

c:153

"mpc prev && /home/xxx/scripts/prev"

c:144

"/home/xxx/scripts/conk"

c:230

"/home/xxx/scripts/clock"

c:178

"mpc del `/home/xxx/scripts/delete`  && /home/xxx/scripts/deleted"

c:237

"/home/xxx/scripts/random"

c:160

"/home/xxx/scripts/now_playing"

c:229

"/home/xxx/scripts/shot win"

c:111

"/home/xxx/scripts/shot scr"

c:78

"ding -x -R -m"

control+Super_L

"amixer -c 1 set Master 1-"

c:174

"amixer -c 1 set Master 1+"

c:176

##################################

# End of xbindkeys configuration #

##################################

```

Using "xev", it's no hassle to include the mousebuttons and wheels too. (For my G7, everything worked ok out of the box, so i didn't have to alter the mousebuttons).

***edit: ***

on the wiki, there are some entries for adjusting mousebuttons and stuff. Maybe take a look there for your unrecognized buttons.

----------

## Dralnu

 *stahlsau wrote:*   

> hi,
> 
> nice howto.
> 
> Few ideas from myself: why not using xbindkeys? Most people have got that installed for their multimedia-buttons on the keyboard already, and it doesn't have a that cryptic configuration file (did i say that i hate xml already? ).
> ...

 

While you can, there are some buttons that don't generate a keycode or anything (I checked via dmesg when xev didn't output anything).

Also, getting the buttons to all work right (like the hyper-scroll keys) is a pain since they share with the cursor keys or some other such key (if you knw how to get the two to generate diffrent codes, or even get them to just generate output other then a keycode (forgot the term for it, if you didn't notice), that would be great).

Ihad a map of all the keys, their keycodes, or the dmesg output you get from them. Unfortunatly, I think it got trashed, but I do know that there are a series of keys that generate no output, and there are some other keys that share codes that wouldn't.

Also, the mouse, the hyper-scroll buttons on it doesn't generate any codes whatsoever (the scrollwheel on the mouse and keyboard share the same output. It would be nice to link the keyboard into bash/screen so use for a scrollback instead of the other forgotten key combo. Also good for elinks).

----------

## psychomunky

While this tutorial is for keytouch, you may still find it useful for other software.  I suggest the following, even if you use lineakd or xbindkeys and not keytouch:

 Plug your keyboard into PS/2 ports, rather than USB...yes USB is nice and arguably preferable, however, the current keyboard driver is somewhat broken, and does not register events for all keys on many keyboards (expecially ones like the MX3000 with lots of extra keys).

 Use the config file I posted above (I know some of you hate XML, but deal with it....it isn't going away at the moment) to figure out the scancodes.  You can then bind these scancodes to keycodes (or just use the scancode->keycode bindings I used).  Finally using you favorite key binder (keytouch, xbindkeys, lineak, etc) bind your keys to actions.

With the bindings in the keytouch config file above, I have EVERY single one of the keyboard keys generating an event.  There are however, two keys that generate the same scan code (the media button and the one that looks like a remote control), which means that they are the same key, but all others are unique.

As mentioned, I haven't yet tried getting the mouse working 100% yet.  Before I do that, it I will put together an image of keyboard and its scancode mappings.  I'll also include the keycode mappings I used.

stahlsau, thankyou for your suggestions and tips.  I do have one question for you though: Are you using an MX3000 keyboard with xbindkeys??  Just curious, as there doesn't seem to be enough keys in your xbindkeysrc for the full gamut of MX3000 keys.

----------

## Dralnu

FWIW: They hyperscroll buttons on the mouse DO work (odd, isn't it?), but they don't generate keycodes. They do generate your normal mouse button codes, though (8 and 9, actually)

----------

## psychomunky

Dralnu,

Thanks for the info on the mouse buttons...I m going to start playing with the x.org config to get everything working with it now...any suggestions for the x.org config and the mouse plugged into a PS/2 port??

BTW, have a look near the end of the first post....I created an image with the scancodes mapped to the multimedia keys on the keyboard.  Let me know if you need more info on this image, such as the scancode->keycode mappings I used.

- Munky

----------

## psychomunky

*Bump* due to updated tutorial.

New this time around:

- preliminary sections on using LineakD and xbindkeys with the keyboard.

- Mouse configuration for X is 100% done.

- Instructions on re-mapping mouse buttons is 90% complete (still need to do a bit of testing).

----------

## Dralnu

Need to add in you need evdev in INPUT_DEVICES in make.conf, otherwise X will hardfreeze.

----------

## gd96

Im using gnome (what can I say I like the clean look  :Very Happy: ) , and my other favorite app which I cant live with out(yes there is a linux app that keeps me from using windows ) Amarok. Now your probably wondering..is there a point here? well yes there is, the multimedia keys(next song , play , etc.) just keep spawning  new versions of Amarok!!!  Is there anything I can do about that?

other than that keep up the good work, cause this app is pretty sweet!

----------

## Dralnu

 *gd96 wrote:*   

> Im using gnome (what can I say I like the clean look ) , and my other favorite app which I cant live with out(yes there is a linux app that keeps me from using windows ) Amarok. Now your probably wondering..is there a point here? well yes there is, the multimedia keys(next song , play , etc.) just keep spawning  new versions of Amarok!!!  Is there anything I can do about that?
> 
> other than that keep up the good work, cause this app is pretty sweet!

 

Check your setting. Either you linked the hotkeys to exec amarok, or they are all set up to the same key.

----------

## bjorntj

I have followed your instructions and now my mouse works ok... But not in several java programs... When using the scrollwheel, scrolling down does what is expected but trying to scroll up, brings up the context menu for the application (i.e. the same as when right clicking with the mouse). This happends only in some java apps and works as it should otherwise...

Any solution for this?

BTJ

----------

