Sunday, October 22, 2006

Extra Keys

Ever wanted to use those extra keys (like volume, Internet etc.) on your keybord? Well, there are many ways to do this. The easy way (KDE) : Open the Control Center, go to Regional and Accessibility -> Keyboard Layout and choose your keyboard from the list. The hard way: Use this if your keyboard isn't listed there or you dont use KDE (there IS an easy way in GNOME too, but since I dont use it, I dont know it). Open up a terminal and run "xev" in it. Press the key you want to use and carefully note the keycode displayed on the terminal. Now, use "xmodmap" to set the key to a Keysym. For example, let's say you opened xev and pressed the "Volume +" key, and got this output:

KeymapNotify event, serial 31, synthetic NO, window 0x0,
keys:  2   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
       0   0   1   0   0   0   0   0   0   0   0   0   0   0   0   0

KeyRelease event, serial 31, synthetic NO, window 0x2c00001,
root 0x44, subw 0x0, time 1901594635, (767,132), root:(771,602),
state 0x0, keycode 144 (keysym 0x1008ff4a, XF86LaunchA), same_screen YES,
XLookupString gives 0 bytes:
Note the keycode. Now, lets say you want to set the Keysym of key 144 to XF86AudioRaiseVolume (you can find more Keysyms in /usr/X11R6/lib/X11/XKeysymDB (debian) or /usr/share/X11/XKeysymDB (fedora)). The following command will set the "Volume +" key to raise the volume (on KDE, this launches kmix and then raises the volume, with a huge dialog (which lasts for about 0.5 seconds) telling you the current volume):
# xmodmap -e "keycode 144 = XF86AudioRaiseVolume"
If you dont want the huge dialog, then you can use the panel's volume setter to use the key (set it's keysym to something arbitary like XF86Launch0) to increase the volume.

Keyboard LEDs

Ever made a script which runs in background, but you want it to tell you the status every now and then? Most likely, you'll resort to emailing the status to yourself. But, emailing isn't really convinient when all you wanna know is if it is on or not or something like that. Something that is far more convinient is setting the keyboard LEDs. The program which sets the keyboard LEDs is "setleds". You have an option of setting only the LEDs and not the flags (capslock, numlock etc.). However, I've not been able to find a way to actually toggle the flags when running X. Moreover, this requires you to set UID on the setleds binary (or run it as root in any other way). For example, to the set the numlock LED to on, run the following command:

# setleds -L +num < /dev/console
You can have a look at my script which gives an example of how to use this program in scripts (this script blinks the keyboard LEDs in the given sequence or randomly).