« November 2008 | Main | January 2009 »

December 17, 2008

Hidden Linux : Programming Multimedia Keyboards


I recently changed keyboards. The new one has a variety of specially labelled multimedia keys. I rarely use these things, preferring to program my own shortcuts that will work on any keyboard, but I also like a challenge.

On the new keyboard -- a Logitech Cordless Internet Pro -- the Mute and Volume keys work fine while the Email key starts KMail (I use Thunderbird). The other keys -- Media, Play/Pause, Favorites and WWW do nothing, so let's get them working...

xev
All keys generate keycodes when pressed (and released) so we first need to see what codes the multimedia keys produce. The tool to use for this is xev -- the X event viewer. Install it, run it from a console window, and it'll display all keyboard and mouse events until you close the Event Test window. (Ubuntu users will find it's part of the x11-utils package.)

Here's what I get when releasing my non-functioning WWW key:

KeyRelease event, serial 31, synthetic NO, window 0x3800001,
    root 0x188, subw 0x0, time 34924258, (169,-18), root:(175,11),
    state 0x0, keycode 178 (keysym 0x1008ff2e, XF86WWW), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

The keycode is really all the information I need, but also notice the keysym (key symbol). Not every key produces a keysym.



xmodmap
If you want to display and edit keycode-to-keysym mappings, you'll need xmodmap. Install it, (it's part of the x11-xserver-utils package in Ubuntu), and run the following command:

xmodmap -pke > ~/.Xmodmap

This will write all current key mappings to the file .Xmodmap in your /home/username directory. The leading "." makes it a hidden file but you can still access it with a text editor.

Looking at the output file I find

keycode 178 = XF86WWW

which is exactly what xev told me. That's not terribly useful as the key doesn't work anyway, but if it did and I wanted to move its function to a different key, I could do so by simply reassigning the keysym.

To test xmodmap changes right away type;

xmodmap ~/.Xmodmap

Tip: Killing CapsLock

I find the CapsLock key particularly useless. I mean, WHO WANTS TO SHOUT ALL THE TIME? Killing it is simple; just remove its keysym in .Xmodmap. Change

keycode  66 = Caps_Lock

to

keycode  66 =

and you'll never accidentally bump it on again!



xbindkeys
What I really need is something to capture the keycode of the WWW key and associate a program with it. What I really need then is xbindkeys.

Install it, (it's just xbindkeys in Ubuntu), and run the following command to create a default file:

xbindkeys --defaults > ~/.xbindkeysrc

Now take a look at .xbindkeysrc in a text editor. You'll find several examples of the format used at the top of the file. In my case I merely added this to the bottom of the file and saved it.

#Start Firefox when the WWW key is pressed
"firefox"
c:178


To test your settings interactively, type

xbindkeys --nodaemon

(Use Ctrl+C to quit.)

Note that the default examples in .xbindkeysrc reprogram the Ctrl+F, Ctrl+Shift+Q and Ctrl+MiddleMouseButton settings. You might want to comment out those out before you proceed!



Auto-start the new settings
Once you've completed and tested all your multimedia key modifications, you can start them automatically each time you boot by adding the following two lines to the bottom of the .bashrc file in your /home/username directory:

xmodmap ~/.Xmodmap
xbindkeys



<--Previous Hidden Linux      Next Hidden Linux -->


December 4, 2008

OOo 3 and the joys of open source

I recently upgraded to OpenOffice.org 3, and amongst the raft of new and enhanced features is the Extension Manager -- under the Tools menu -- that handles all manner of add-ons, including dictionaries. Then I hit a snag: no dictionary for New Zealand English. There's English-English, Aussie-English, US-English but nothing for NZ. Never mind. This is open source. I built my own!

Actually that's a slight exaggeration. Oh, all right, it's a huge exaggeration. In the best traditions of open source I merely stood on someone else's shoulders.

The NZ English dictionary in OOo 2 was compiled by Tristan Burtenshaw who localised the original English one by adding a ton of Kiwi place names, Maori terms and local lingo. I tried contacting him via the email address in the accompanying README file but my message bounced. (If you're out there Tristan, I hope you don't mind!)

As a piece of programming, creating an Extensions format NZ dictionary was remarkably straightforward. I simply took Tristan's OOo 2 dictionary files, popped them in an OOo 3 Extensions container and tweaked a couple of the controlling files. (You'll find more details here if you're technically inclined.) I then uploaded my creation to the OOo Extensions server and within 24 hours more than 100 people had benefited from my labour.

You'll find the new NZ dictionary here. I'm currently looking at updating and maintaining it so if you find any errors, omissions or have any other suggestions, let me know.

(And if you need help with spell checking and language configuration, try this link.)

December 2, 2008

Hidden Linux : Doing the joins


Some time back, in a blog entry entitled Doing the Splits, I described how a great little command line tool called mp3splt could be used to break large MP3 files into more manageable pieces -- even picking out natural track breaks as it went. Recently I've been wanting to do the opposite, so I added mp3wrap to my arsenal.

Mp3wrap combines two or more MP3s into one large ouput file without losing the original file names or ID3 information. It then adds the string "MP3WRAP" to the output file name. Why? Because if you later run the wrapped file through mp3splt using the -w parameter, all the original files will be restored exactly as they were before!

Of course if you don't want the unwrap facility you can simply rename the output file.

The command format is simple:

mp3wrap  album.mp3  a.mp3 b.mp3 c.mp3 d.mp3

will combine tracks a.mp3, b.mp3, etc into a single large file called album.mp3. Or you can use the verbose parameter so the program tells you what it's up to.

mp3wrap -v album.mp3  a.mp3 b.mp3 c.mp3 d.mp3

Install mp3splt and mp3wrap via your distros' usual repositories. And Windows users aren't left out. Versions of both available for them too from the projects' homepages. (Click the links above.)



<--Previous Hidden Linux      Next Hidden Linux -->


Subscribe
Newsletter & SubscriptionsPC World is New Zealand’s top selling computing and technology magazine.

It provides up-to-the-minute editorial, insight and buying advice for personal computing, cell phones, game consoles, digital entertainment and broadband.
SIGN UP
PCWorldUpdate
PC World's weekly round-up of tech news, gear and game reviews, software selections, and handy How Tos.