Wednesday, 3 July 2013

Fixing the dead backslash and bar key on AIX 5.3

So the other day I was upgrading AIX on my IBM RS/6000 model 7046-B50 (actually, two of them) to 5300-12-05 and discovered that the system was rather rudely ignoring my attempts to type either a backslash or a bar. For a Unix system, this is quite a problem.

My system configuration is the aforementioned B50 connected through a StarTech SV831HD KVM switch to an IBM model M keyboard (built August 31, 1992 - nearly 21 years old and going strong, fantastic keyboard), a Microsoft optical mouse and an ASUS LCD monitor.

After poking around the internet for a solution I realised, unsurprisingly, that I'm not the only one to have experienced this phenomenon. What I realised subsequently was that there was very little in the way of a solution available. What I did determine was that the culprit was the wonky keymap file supplied by IBM. That was referenced a couple times. But how was I to fix it?

Step 1: What's the correct bloody keycode?

A short search led me to a tool called xev that reports on X events such as mouse movements and key presses. This will tell you what the keycode for the inactive backslash/bar key is. But first, you have to install the package that contains xev. It is not installed by default.

The package in question is X11.samples.apps.demos. I used Smit to install this from the AIX 5.3 media.

Now that xev is installed you merely need to execute it. The path is:

/usr/lpp/X11/Xamples/bin/xev

A small window pops up and you'll notice that if you move the mouse around or type keys a stream of text flows onto the shell. We're only interested in the keypress event when we type the backslash/bar key. This is the output I was interested in:

KeyPress event, serial 18, synthetic NO, window 0x3800001,
    root 0x29, subw 0x0, time 2798287790, (19,-20), root:(148,109),
    state 0x0, keycode 22 (keysym 0x0, NoSymbol), same_screen YES,
    XLookupString gives 0 characters:  ""

KeyRelease event, serial 18, synthetic NO, window 0x3800001,
    root 0x29, subw 0x0, time 2798287878, (19,-20), root:(148,109),
    state 0x0, keycode 22 (keysym 0x0, NoSymbol), same_screen YES,
    XLookupString gives 0 characters:  ""

And the most important part is highlighted. That's the keycode that is supposed to be mapped to the backslash/bar key.

Step 2: OK, now how do we make the key work?

Now all we need to do is correct the mapping. To do this we use xmodmap. The syntax is straightforward:

xmodmap -e 'keycode 22 = backslash bar'

Let's decipher this:

xmodmap
This is the command to execute, naturally.
-e
This indicates that what follows is an expression to be run.
keycode 22
We're going to state what keycode 22 should produce when typed.
backslash
The unshifted character to be typed is backslash.
bar
The shifted character to be typed is bar.

Note that the entire expression needs to be in quotes.

After executing the xmodmap command I had a fully functional backslash/bar key!

A couple notes about this:

  • This is a temporary fix. The next time you start X the keymapping will revert to the default. A permanent fix requires changing the keymap definition file. I haven't bothered to go that far yet.
  • This only works within the X session. If you log in from the console this will have no effect.

Because this change is transient I created a script to run. It's pretty basic:

#!/bin/sh

echo "Correct keymapping for backslash and bar."
echo "     xmodmap -e 'keycode 22 = backslash bar'"
xmodmap -e 'keycode 22 = backslash bar'

No comments: