Ok, so I bought a Media-Tech NEMESIS USB headphones. They work really great (even the microphone now works on Linux) except there’s this one button that lunches Windows Media Player on Windows but on Linux… it doesn’t seem to do much… And since there’s no software to configure it (at least not to my awareness), it was a time to call the programmer in me :)

Why don’t we jump right into it. First thing we need is to get the actual keycode that is sent via USB when we press the button. I will be using theĀ Xev tool that should come pre-installed on every Linux system that uses X. Xev is not really for every day use, i’ts more of a testing/debugging tool but it should do just find. It will create a window and ask the X server to send it events whenever something happens on the window, like keystrokes which is exactly what we are after.

So once we get the keycode (mine was 179) we need to tell our system to do something once it’s pressed (or once we see it in the log files). For that purpose I have written a little shell script that should work on most *UNIX machines (Linux, Mac, BSD) perhaps with a bit of editing.

#!/bin/bash
do_the_thing () {
echo “Checking for Keycode 179….”
FN=`grep “keycode 179″ /home/queenz/Desktop/mt_output`
length=$(echo ${#FN})
if [ $length -gt 10 ]
then
echo “Key triggered, executing…”
xdg-open “http://www.QueenZSoftware.com”
echo ‘empty’ > /home/queenz/Desktop/mt_output
fi
sleep 5
wmctrl -a Event
do_the_thing
}
do_the_thing

How to run the script

1. cd to the script directory and issue the ./script.sh command (or whatever you called your script). This will start looking for the keycode entry in our log files.
2. execute the xev > logfile. This will record all your keystrokes.

Important!
You need to have your window focus on the X Window or it won’t work!

Also works by adding an entry in System > Preferences > Keyboard shortcuts under GNOME.

-Martin

« »