Targus presenter as volume control

This is a little project to make use of a Targus wireless presenter. Its model is PAUM35 and it uses radio for transmitting data to the computer. (http://www.epinions.com/reviews/Furniture-Ergonomics-All-Targus_PAUM30U_WIRELESS_REMOTE_PRESENTER)
In this device there is a laser pointer, a four way button that moves the mouse pointer and two buttons (mouse left & right). There is also a button to switch mode of the device.

The point of this project is to use the device as a volume control for a headless music computer that runs Debian. If the receiver is plugged into a computer with X it acts like a mouse, no configuration needed. But here we want to use it as a volume control, no graphics involved.

At first the program xev is used on a usual computer to see what happends. The interresting find is that in one of the modes the left & right buttons sends keypresses:

KeyPress event, serial 35, synthetic NO, window 0x4000001,
root 0xa5, subw 0x4000002, time 467048535, (41,29), root:(464,264),
state 0x0, keycode 117 (keysym 0xff56, Next), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False

KeyRelease event, serial 35, synthetic NO, window 0x4000001,
root 0xa5, subw 0x4000002, time 467048735, (41,29), root:(464,264),
state 0x0, keycode 117 (keysym 0xff56, Next), same_screen YES,
XLookupString gives 0 bytes:
XFilterEvent returns: False

KeyPress event, serial 35, synthetic NO, window 0x4000001,
root 0xa5, subw 0x4000002, time 467049231, (41,29), root:(464,264),
state 0x0, keycode 112 (keysym 0xff55, Prior), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False

KeyRelease event, serial 35, synthetic NO, window 0x4000001,
root 0xa5, subw 0x4000002, time 467049471, (41,29), root:(464,264),
state 0x0, keycode 112 (keysym 0xff55, Prior), same_screen YES,
XLookupString gives 0 bytes:
XFilterEvent returns: False

We have keycode 112 for one button, 117 for the other.
To make the buttons control the volume the software lineakd is used (can be installed with Apt).
Then the directory .lineak is created and so also two files:

/home/patrik/.lineak/lineakkb.def:

[PAUM35]
brandname = "Targus"
modelname = "PAUM35"
[KEYS]
AudioLowerVolume = 112
AudioRaiseVolume = 117
[END KEYS]
[END PAUM35]

/home/patrik/.lineak/lineakd.conf:

KeyboardType = PAUM35
AudioLowerVolume = /usr/bin/amixer set -c 0 set PCM 2-
AudioRaiseVolume = /usr/bin/amixer set -c 0 PCM 2+

When the files are created and saved, lineak is started with the command "lineakd".

*BUT*
Here we find a problem, lineakd needs X to run.

sudo showkey
tangentkod 109 tryck
tangentkod 109 släpp
tangentkod 104 tryck
tangentkod 104 släpp

/etc/mykeys:
string F100 = "/usr/bin/amixer set -c 0 PCM 2+"
string F101 = "/usr/bin/amixer set -c 0 set PCM 2-"

keycode 109 = F100
keycode 104 = F101

The load the keys:
sudo loadkeys /etc/mykeys

Thanks to https://help.ubuntu.com/community/PlantronicsUSBHeadsetControls and http://codeidol.com/unix/linux-desktop/Console/Energize-Your-Console-with-Macro-Music-Magic/ for inspiration and knowledge.