iTunes & Media Keys

I was really annoyed by something when I got a new Dell PC with XP Media Center Edition. The media keys on the keyboard (like Skip, Back, Play, Stop, etc) didn’t work in iTunes unless it was the active window. In contrast, they did work with Windows Media Player, even if it was minimized (of course).

Since this was wholly unacceptable, I decided to spend a few hours devising a workaround. The result was two programs: iTunesKeys and iTunesCommandPasser (I know, great names). Both are written in C#, using the COM provider built-in to iTunes.

iTunesKeys basically creates a global keyboard hook looking for one of the media keys to be pressed. When that happens, it fires an event and executes the iTunesCommandPasser with a command line parameter telling it to skip, go back, or whatever.

The reason this is in two parts is that you cannot have two things going on via COM at the same time, under the same process. Since I am using COM for the hook, and to pass commands to iTunes, the two pieces had to be split in half. There may or may not be a more elegant way to deal with this, but I didn’t spend much time working on it.

To use the binaries, put the two EXEs and one DLL in the same directory, and launch iTunesKeys.exe. I’ve noticed that it seems to crash if you start iTunesKeys before iTunes the first time, since it probably isn’t registering correctly. I’m going to look at fixing that.

Zips below contain both programs.
Binaries
Source Code

Thanks to Dan Crevier at MSDN for discovering the COM abilities of iTunes.

Share

153 Responses to “iTunes & Media Keys”


Leave a Reply

 

PayPal