Note for English Readers

If I write the articles in Indonesian, I will write a summary in English so that you can read my articles too. After you read the summary and you feel that you need more information about that, please do not hesitate to contact me via e-mail that can be found in my profile.

Thank you for reading my blogs.

Monday, September 24, 2007

How to Set Extra Keys on Laptop

Laptop usually has some extra keys for particular purposes such as volume control, brightness control, sleep button, etc. If you are lucky, you will get all extra keys are working nicely. On my laptop, only brightness control can working.
From Arman Idris' blog, I got an explanation in Indonesian about how to set extra keys on laptop that have Slackware installed and KDE as desktop manager. I think all Linux distros can adopt it if they are using KDE as desktop manager. If you use GNOME, I'm sorry ... I do not know how to set ... please googling :)

The software that we need to activate the extra keys are xmodmap and xbindkeys. Xmodmap are commonly used in X system, so that, we do not need to install it. Xbindkey usually does not included. We need to install it. Get it from http://hocwp.free.fr/xbindkeys/xbindkeys.html then compile and install it. After finishing install xbindkeys, there are some steps to follow:

First, we have to know the keycode of extra keys that we want to activate. From console, type xev then press the desired extra key. On screen we will see some texts like this:
KeyPress event, serial 32, synthetic NO, window 0x2a00001,
root 0x66, subw 0x0, time 335922971, (1083,351), root:(1093,377),
state 0x0, keycode 160 (keysym 0x0, NoSymbol), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False

Pay attention on the bold texts. That is the keycode for extra key that we just pressed, on my laptop, that is extra key for muting volume. Using the same procedure, on my laptop, I found keycode 174 and 176 for volume down and volume up, respectively.

Second, we write 2 configuration files: .xmodmaprc and .xbindkeysrc, place them in the home directory. Here is my .xmodmaprc:
keycode 160 = F14
keycode 174 = F15
keycode 176 = F16
The name of F14, F15, and F16 are alias names of extra keys that have keycode of respectively 160, 174, and 176. For standard naming in xmodmap, please refer to xmodmap manual.
My .xbindkeysrc can be found here:
#Volume Mute
"/usr/local/bin/mute.sh"
F14
#Volume decrease
"dcop kmix Mixer0 decreaseVolume 0"
F15
#Volume increase
"dcop kmix Mixer0 increaseVolume 0"
F16
Note that dcop can be found only in KDE.
Since we do not have script file mute.sh, we have to write it then place it to /usr/local/bin. Do not forget to change file permission using: chmod 0755 /usr/local/bin/mute.sh -- of course, you must have root permission to execute this command --
Here is the script of mute.sh:
#/bin/bash
MUTE=`dcop kmix Mixer0 mute 0`
if $MUTE -eq "true" ; then
dcop kmix Mixer0 setMute 0 off
else
dcop kmix Mixer0 setMute 0 on
fi
This script will toggle the mute status when we press the mute key. For instance, if the last status is "mute", the status will change to "unmute" when we press the mute key.

Third, we edit the .xinitrc (you can found it in your home directory) to run configuration files that have been written. Here is my .xinitrc:
#!/bin/sh
# $XConsortium: xinitrc.cpp,v 1.4 91/08/22 11:41:34 rws Exp $

userresources=$HOME/.Xresources
usermodmap=$HOME/.xmodmaprc
sysresources=/etc/X11/xinit/.Xresources
sysmodmap=/etc/X11/xinit/.Xmodmap

# merge in defaults and keymaps

if [ -f $sysresources ]; then
xrdb -merge $sysresources
fi

if [ -f $sysmodmap ]; then
xmodmap $sysmodmap
fi

if [ -f $userresources ]; then
xrdb -merge $userresources
fi

if [ -f $usermodmap ]; then
xmodmap $usermodmap
fi

/usr/local/bin/xbindkeys -f $HOME/.xbindkeysrc

# Start the window manager:
startkde

The bold lines are the lines that have been added by me.


Last step, restart X, then enjoy your extra keys :)


Reference:

No comments: