Created another open source utility key-mon

This weekend I was watching screencasters.heathenx.org a video podcast about Inkscape with the Miro player. Heathenx had to apologize that his key status monitor wasn't displaying mouse activity.  This wasn't the first time I've seen problems with this utility, earlier in the year Meet the Gimp also had some problems getting it to work.

I downloaded the program and put in on my machine, and sure enough the mouse wasn't working for me either. Looking at the output, it complained that I have more than one mouse and it was going to pick the last one.  It lied, I looked at the code and it actually picked the the first one. I changed the code so that it did pick the last mouse and it worked.  I thought of submitting a patch, but I realized that arbitrarily picking the last one might break the program for others for which it was working.

To my delight the code was written in Python, using PyGTK. It wasn't even that much code, I could probably write a similar program to from scratch in a day. I've never used PyGTK (I mostyl have used wxPython), but a little googling showed that it is definitely the better choice in this case. PyGTK is already installed on most linux boxen (unlike wxPython).

At that point I started cataloging the issues I saw with the program:
  • Doesn't support the Meta (aka windows key).
  • Doesn't support the scroll wheel, something that's used quite a bit in graphics programs.
  • Need to be root to run it.
  • There's no open repository (like code.google.com) to submit patches or issues to.
  • Doesn't have a context sensitive menu, you can only change options at the command line.
  • The window is not re-sizable.
  • If you don't care about the mouse or certain keys - you are out of luck.
The original code kept all the images as PNG files, which is ok, but a little bit of playing around I discovered that GTK+ supports SVG extremely well (alpha transparencies and all).  I realized that I could create the images on the fly directly from the svg files!

Instead of having 6 large images for the mouse (normal, left-button, right-button, middle-button, scroll-up, scroll-down),  I would need only one for the mouse and 5 other smaller pieces for the buttons and scroll wheel. GTK obeys the SVG document size, so I just need to make them all the same size and everything should overlay in the right location (code).

It also means that I the potential to make the window re-sizable.  If the images are two small, I can make the bigger - too large, I can make them smaller (although I haven't done this yet).  For many of the keys I can just search and replace the SVG contents to show different text, reducing about 100 keycap images that I would have needed to create.

The original code used the evdev module by Micah Dowty. With a quick code search I found a more recent version of this module.  With this version I could throw it all the keyboards and mouses and it would track them all, thus fixing the mouse problem.  Running it's built in demo showed that I could easy keep track of the meta key and the scroll wheel as well.  Also, on my machine, I didn't need to be root to run the program another bonus.

I still have some work to do on it (more keys, packaging, refactoring). Here's what it looks like so far:  The pale buttons is just the lower dark buttons with a white semitransparent rectangle on top.






It's amazing what you can code in a day these days.
Visit to http://code.google.com/p/key-mon/ and have a look.

Comments

heathenx said…
Brilliant, Scott! :)

Popular posts from this blog

Shortest Sudoku solver in Python

Seven Segment Display in Inkscape