molotov
July 9th, 2004, 19:06
A bit of history, prompting this write up.
First of all, I use a laptop a lot of the time, and I find the little mouse really bothersome. So I started looking for a more keyboard based window manager and I found Ion (http://modeemi.cs.tut.fi/~tuomov/ion/). Ion uses mainly what are your Mod Keys, or Modifier keys. In other words, keys, that when pressed in conjunction with other keys, yeild diffrent results. The primary example would be the Alt key. Most people use some program where there is a shortcut using the alt keys. This presented a problem, because I was very used to hitting Alt+Left/Right arrow to go back and forward in firefox, and Alt+numbers to change conversations in Gaim. So I Began to look for another key to bind to Ions default modifier key, when I stumbled across the "Fn" key on my laptop. And here is where the fun begins...

After a bit of googling, I found the first thing to needed to remap a key is the keycode. There are 2 levels going on when you hit a key on your keyboard, and from bottom to top
-keycode
-keyname

The keycode is the hardware signal sent to the computer, and the keyname is what X translates the key into. So for starters, we had to find the keycode, so we used an app called xev, or X Event Viewer, which comes with XFree86. Doing this, and hitting my function key, I found out it was keycode 227, and it was bound to NoSymbol (0x0). The next job was to use xmodmap, or X modify keyMap to remap it. Xmodmap is meant to read input from a file, but you can pass arguments to it with the "-e" option. So for starters I ran

xmodmap -pk

to see what was unused. Then, I looked through /usr/X11R6/include/X11/keysymdef.h to find a defined key that was not bound on my keyboard. I was going to make this key a Modifier key, so I found an unused key in the modifier key section, Hyper_L or in hex, 0xFFED. Next, after reading the xmodmap man page (which is excellent) I found the syntax to map a key. and away I went with

xmodmap -e "keycode 227 = Hyper_L"

Now, when I ran xev and hit my "fn" key or ran xmodmap -pk and looked next to key 227 I could see that it was indeed Hyper_L, or 0xFFED. Now I had my function key bound to a key that was not on my keyboard. In retrospect, the eleation I felt seems silly, however at the time it was amazing. Now, I just needed to see what Mod keys were open for binding. I ran

xmodmap -pm

and I could see that I had both Mod3 and Mod5 open. after rechecking the xmodmap man page, I decided on Mod3

xmodmap -e "add Mod3 = Hyper_L"

and after running xmodmap -pm I could indeed see that I had remapped Mod3. Victory I though, but alas it was not to be so. After a bit of testing and yelling, I realized my problem. The "fn" key on my laptop is not a good Mod key. I had indeed mapped it to Mod3, however what had earlier escaped my notice was that when in xev when I hit the "fn" key it did both the press and release regardless of weather or not I pressed and released it. It was a key that could not be held down basically. So I searched my keyboard, and I couldnt remember the last time I had used my capslock key, so away it went.

xmodmap -e "clear Mod3"
xmodmap -e "remove Lock = Caps_Lock"
xmodmap -e "add Mod3 = Caps_Lock"

then I just editied my ion config, and bang! caps lock was now my Modifier key for ion, and my alt keys worked again :) Life is grand.

This is my first howto, so slash away, Id like to hear how to make them better

molotov
July 10th, 2004, 01:36
i forgot to mention this howto is only for X. I can add a console one if there is any intrest.