Thursday, 31 December 2009

Naughty [NumLock] key on Thinkpad R50e running Ubuntu

It's been a constant pain in the proverbial to use this Thinkpad R50e, running Ubuntu 9.04, with and without an external keyboard.

It spends much of its life fixed to a desk with an external USB keyboard, connected via a four port USB hub/speaker combination. In this manner, the [NumLock] key needs to be pressed ( on the external keyboard ) for the numeric keys to be usable.

However, when the hub etc. is unplugged e.g. when the laptop goes on the road, the [NumLock] light stays illuminated, meaning that the numeric keys on the Thinkpad's own keypad become activated, preventing half the keyboard from being used for its proper purpose e.g. the U key becomes a 4, the K key becomes a 2 etc. etc. etc.

The problem is that it's not easy to disable [NumLock] from within the Gnome X11 environment - switching to another virtual terminal using [Ctrl][Alt][F1] etc. sometimes works, but that's not a particularly elegant solution.

There are probably better ways, but a Google search found me NumlockX
which does the job far more elegantly.

I installed it as follows: -

sudo apt-get install numlockx

It has three parameters, easily displayed using the command numlockx -? which are: -

on - turns NumLock on in X ( default )
off - turns NumLock off in X
toggle - toggles the NumLock on and off in X

However, I didn't want to have to open a shell merely to do this, so I wrote a simple script: -

#!/bin/bash
numlockx off

saved as numlock.sh which, having set as executable ( chmod +x ) in my user's home directory, I then created a desktop shortcut ( via a Custom Application Launcher ) to it.

I placed this shortcut on the bottom panel, alongside Firefox, Thunderbird, Open Office, Skype etc. and now have a simple way of toggling the NumLock off.

If I wanted to, I could have amended the script to read: -

#!/bin/bash
numlockx toggle

to that I could change the state on AND off, at the click of a mouse button.

Simple ....