Binding function keys to commands

Posted by: Cesar Oliveira
Poster contact info: cdolivei at learn dot senecac dot on dot ca
Author: same as 'Posted by'
Software: Slackware 10.1

This is a bad way of getting function keys working in slack.

You need to follow three steps to get function keys to work :
1. find out the keycode
2. associate that keycode with a keysym
3. associate a keysym with a command (eg. amixer to raise/lower volume)

Finding out a keycode:
xev is a great command line tool for this. xev opens up in a new window. When you hit a key, mousebutton, or function key you should get a single keycode. For example, on my system function + volume up is 176 and function + volume down is 174.

Associate keysym with a keycode:
You need to use a command called xmodmap. Running 'xmodmap -pke' will tell you what each of your keycodes are associated with. Working with my laptop, we map 176 with F86AudioRaiseVolume with the following command
xmodmap -e 'keycode 176 = F86AudioRaiseVolume'
When that is done, you have to save the changes because they get reset when you restart your machine.
xmodmap -pke > ~/.xmodmaprc

A list of keysyms:
You can get a list of these keysyms in /usr/include/X11/XF86keysym.h. XL_ is either removed or optional, I don't remember.

Associate a keysym with a command:
Try to use your function keys. Don't despair if it does not work. You need to tell slack to run a certain command when that key is hit. This can be done using a program called xbindkeys, which is a quick download and build.

First you must make a default bindkeys file in your home directory. This is checked when xbindkeys is loaded.
xbindkeys -d > ~/.xbindkeysrc
Open that up. If you were to start xbindkeys now, the defaults take place, which I don't particularly like. Remove them if you wish. The syntax for the configuration file is as follows.
"command"
[ keysym | key combinations ]

You can get key combinations by passing -mk. Here is an example to get volume increased using alsa:
"amixer -q sset 'Master' 10%+1"
XF86AudioRaiseVolume


Running xbindkeys goes into daemon mode, so pass -n to test it. If everything works properly, put the following into your .profile :
xmodmap ~/.xmodmaprc
And the following in ~/GNUstep/Library/WindowMaker to load xbindkeys when you are authenticated :
xbindkeys

This is still a bad way because I can't get play/pause/forward/etc to work for different applications.

Cheers