Yahoo Media Engine and media keyboards
I’ve been playing with Yahoo Music (Update 7/11/2011: The product this post refers to was shut down in 2008). It’s nice enough but it is really irritating that it doesn’t pick up the Play/Next Track/Previous Track/etc buttons on my keyboard when YME does not have focus. WMP does and I’ve gotten used to using those buttons to control music playback while using other apps (such as City of Heroes). Thus begins my path to figure out how hard it would be to write a plugin for YME that picks up those keyboard events even when YME doesn’t have focus.
Simple enough, right? It’s probably easy if you already know how to do it…
I initially looked for those media buttons to be exposed as an obvious API, but it looks like they’re just keys. A bunch of reading and searching eventually led me to SetWindowsHookEx as a way to intercept all keyboard events.
It looks like I won’t (easily or safely) be able to use SetWindowsHookEx from Python’s Win32 module. There’s no wrapper for it and the other alternative (ctypes) does not appear to be stable enough for me to want to use it to hook every keyboard event on my PC. I’ll have to write it in C++ unless I want to require .NET for this tiny little hack.
So, the next step for me is to resume tracking down the relevant keycodes for those Next Track, Previous Track, Pause/Play, and Stop buttons. I’d like to find actual documentation rather than writing the keyboard intercepter and just looking at the keycodes those buttons send.
After that, I’ll need to figure out if I can safely write something inside a YME Plugin to install (and uninstall on unload) a keyboard hook using SetWindowsHookEx and pick up those keypresses. At that point, it’s just a matter of using the YME plugin API’s calls for controlling playback.
I’ll probably discover along the way why Yahoo didn’t do this themselves. I have to assume the reason their app is missing this obvious feature is that there’s some pitfall that I don’t know enough of Win32’s dusty corners to be aware of that makes picking up these keypresses a bad idea.