I will describe how I went about getting my function keys working (in Openbox on Gentoo).
Grab a piece of paper and a pen to write some stuff down on.
First, I had to get the key codes for each key. Go into the terminal and type `xev` while X.
Push the function key you would like to use and a bunch of output will be displayed, it will look something like this
Code:
KeyPress event, serial 30, synthetic NO, window 0x1600001,
root 0xb6, subw 0x0, time 26832051, (88,71), root:(999,512),
state 0x0, keycode 233 (keysym 0xff54, Down), same_screen YES,
XKeysymToKeycode returns keycode: 104
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
KeyRelease event, serial 30, synthetic NO, window 0x1600001,
root 0xb6, subw 0x0, time 26832131, (88,71), root:(999,512),
state 0x0, keycode 233 (keysym 0xff54, Down), same_screen YES,
XKeysymToKeycode returns keycode: 104
XLookupString gives 0 bytes:
for each key press and release (note: make sure not to move your mouse, it will also debug that information). The information you want is in red, above. The critical information that you will probably want to write down is:
Key Function : Key Code : F-key Map
The F-key map will be described later. For now, just get all the keycodes for each key and their respective function.
Then fire up your favorite text editor, hopefully vi :p and make the file ~/.xmodmap, make sure you aren't root'ed, because it will make that file in the root folder and your user won't have it.
Now, this file will map that keycode to an F key of your choice. My keyboard runs up to F12, so I started mapping from F13 and up. The .xmodmap file (period should be leading the filename, that isn't a typo) should look something like this:
Code:
keycode 160 = F14
keycode 174 = F15
keycode 176 = F16
keycode 130 = F13
keycode 236 = F17
keycode 222 = F18
keycode 223 = F19
keycode 227 = F20
keycode 153 = Next
keycode 162 = space
keycode 164 = S s
keycode 144 = Prior
keycode 233 = Down
keycode 234 = Up
keycode 161 = F27
keycode 230 = F28
keycode 122 = F29
Notice the F keys. Next, space, Prior, Down, and Up are all X functions.
Next = Page Up
Prior = Page Down
Up = Arrow Up
Down = Arrow Down
S s means default to capital S when pushed, lowercase s when holding SHIFT.
Those are all just for controlling Xine and Firefox moving up and down with the keyboard. You don't necessarily need them for what you are doing. The data on the right side of the = will be different for you, as will the keycode numbers. Once you have that set up, you need to tell your window manager what you want each F-key to do (in the case of the Next, S s, Up, Down, etc. they are built in and don't need anything more done with them). Every window manager uses different shortcut keys, I can't describe exactly how yours works, unless you tell me what you are using.
For mine, I have Openbox, so I edited my ~/.config/openbox/rc.xml file, this is what one shortcut looks like:
Code:
<keybind key="F27">
<action name="execute"><execute>/usr/bin/xcalc</execute></action>
</keybind>
Your configuration file will need edited in another way, that is just an example for the sake of completion.
Now, for those pesky volume keys, I have a couple scripts that will adjust the sound for alsa using amixer. The scripts are below, first you need to put them in your /usr/local/bin or /usr/bin or any other place in your $PATH and do the following:
Code:
chmod +x /usr/bin/<script-name>
where the <script-name> is the name of the script, for example, /usr/bin/mute. All chmod +x does is make the file executable.
Mute Script:
Code:
#! /bin/bash
declare -r TEMPVOLFILE="~/volume.tmp"
declare -r CURRENTVOLUME=$(amixer get Master | grep 'Mono:' | cut -d' ' -f5)
declare -i NEWVOLUME
if [ "${CURRENTVOLUME}" == "0" ]
then
if [ -f ${TEMPVOLFILE} ]
then
NEWVOLUME=$(cat ${TEMPVOLFILE})
else
NEWVOLUME=50
fi
amixer set Master ${NEWVOLUME}
else
echo ${CURRENTVOLUME} > ${TEMPVOLFILE}
amixer set Master 0
fi
exit 0
That makes the file volume.tmp in your home directory and stores the current volume level of the Master line in it for when you want to unmute (it doesn't work like Windows, there is no real mute/unmute for Linux sound). It then sets the volume to 0, when you press the mute key again, it grabs the number from the file and sets it, if the file is gone, it sets it to a default of 50, or 50%.
Volume Up:
Code:
#! /bin/bash
amixer set Master 1+
exit 0
Adds 1 to the current volume.
Volume Down:
Code:
#! /bin/bash
amixer set Master 1-
exit 0
That is all it takes. The rest of the keys you will just bind like I showed you above to your current window manager according to their path. The final step is to run `xmodmap ~./xmodmap` and preferably put that in your .xinitrc to start up when your window manager starts.
Good luck, HTH.