Tuesday, February 22, 2011

Key mapping and binding in Openbox

If you have used Linux for any amount of time you will know that there are little vendor support and this can be frustrating if you would like to use all 18 000 keys on your brand spanking new keyboard!

I have this keyboard, the Microsoft Natural Ergonomic 4000, and we know that Microsoft will not have any support for it under any other operating system save Windows, hey, do not look at me like that, they actually make some decent keyboards!


So, we will have to map and bind all those extra keys ourselves.

Luckily, binding keys in Openbox is actually a fairly simple task, you only need xev and your favourite editor. This is going to be fast and dirty, but it is really simple and you should have no problems at all.

First of, open the following file:

Code:
# nano -w .config/openbox/rc.xml

Next, run xev, in a terminal just type:

Code:
# xev

You can press one key at a time on the keyboard to get the key code, this is important. The output will look something like this:

Code:
KeyPress event, serial 39, synthetic NO, window 0x2a00001,
    root 0x15a, subw 0x0, time 245502289, (1104,290), root:(1136,701),
    state 0x10, keycode 195 (keysym 0x1008ff48, XF86Launch8), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

What we are interested in is this part:
(keysym 0x1008ff48, XF86Launch8)


Go back the file you opened earlier, scroll down the file until you come across this section in the file:

Code:
<keyboard>
..........
</keyboard>

There will be a lot of text in that section, general Openbox key bindings. You can look over them and change them as you want, remember to make a back-up of the original file first!

Just above </keyboard> at the end of the keyboard section we are going to enter our own custom key binding like this:

Code:
<keybind key="XF86Launch8">
      <action name="Execute">
        <execute>/usr/bin/vlc</execute>
      </action> 
</keybind>

Do this for all the keys. I suggest doing one key at a time for obvious reasons. Log out, log back in and test out all your keys.

Perfect right? Told you it was easy!

Here is the map to all the custom keys on my keyboard.

Code:
<keybind key="XF86HomePage">
      <action name="Execute">
        <execute>/usr/bin/pcmanfm</execute>
      </action>
    </keybind>
    <keybind key="XF86Search">
      <action name="Execute">
        <execute>/usr/bin/chromium</execute>
      </action>
    </keybind>
    <keybind key="XF86Mail">
      <action name="Execute">
        <execute>/usr/bin/thunderbird</execute>
      </action>
    </keybind>
    <keybind key="XF86AudioMute">
      <action name="Execute">
        <execute>/usr/bin/amixer set Master 0</execute>
      </action>
    </keybind>
    <keybind key="XF86AudioLowerVolume">
      <action name="Execute">
        <execute>/usr/bin/amixer set Master 2-</execute>
      </action>
    </keybind>
    <keybind key="XF86AudioRaiseVolume">
      <action name="Execute">
        <execute>/usr/bin/amixer set Master 2+</execute>
      </action>
    </keybind>
    <keybind key="XF86AudioPlay">
      <action name="Execute">
        <execute>/usr/bin/audacious --play-pause</execute>
      </action>
    </keybind>
    <keybind key="XF86Calculator">
      <action name="Execute">
        <execute>/usr/bin/xcalc</execute>
      </action>
    </keybind>
    <keybind key="XF86Launch5">
      <action name="Execute">
        <execute>/usr/bin/vlc</execute>
      </action>
    </keybind>
    <keybind key="XF86Launch6">
      <action name="Execute">
        <execute>/usr/bin/gnome-terminal</execute>
      </action>
    </keybind>
    <keybind key="XF86Launch7">
      <action name="Execute">
        <execute>/usr/bin/soffice -writer</execute>
      </action>
    </keybind>
<!--   Reserved for future use, do not need it now 
#    <keybind key="XF86Launch8">
#      <action name="Execute">
#        <execute></execute>
#      </action>
#    </keybind> -->
    <keybind key="XF86Launch9">
      <action name="Execute">
        <execute>/usr/bin/dcompmgr</execute>
      </action>
    </keybind>
  </keyboard>

You can bind the extra keys on your mouse in the same way in Openbox under the mouse section in that file!
Neat!

No comments: