How do I access (listen for) the multimedia keys (play/pause) in Mac OS X?

2.4k views Asked by At

I want to write a Songbird extension binds the multimedia keys available on all Apple Mac OS X platforms. Unfortunately this isn't an easy google search and I can't find any docs.

Can anyone point me resources on accessing these keys or tell me how to do it?

I have extensive programming experience, but this will be my first time coding in both MacOSX and XUL (Firefox, etc), so any tips on either are welcome.

Please note that these are not regular key events. I assume it must be a different type of system event that I will need to hook or subscribe to.

3

There are 3 answers

0
Gordon Childs On BEST ANSWER

This blog post has a solution:

http://www.rogueamoeba.com/utm/posts/Article/mediaKeys-2007-09-29-17-00.html

You basically need to subclass NSApplication and override sendEvent,
looking for special scan codes. I don't know what songbird is, but if it's
not a real application then I doubt you'll be able to do this.

Or maybe you can, a simple category may suffice:

@implementation NSApplication(WantMediaKeysCategoryKBye)
- (void)sendEvent: (NSEvent*)event
{
    // intercept media keys here
}
@end
1
rami On

xev might help you if you want to find out which codes are being sent by multimedia keys.

0
VVS On

Are you sure your multimedia keys are working in your installation? Every single key generates a scan code which is translated into a key code by the kernel. If xev doesn't show you any keycodes I guess those scan codes aren't mapped and so the kernel has no knowledge of them.

http://gentoo-wiki.com/HOWTO_Use_Multimedia_Keys has a nice explanation of finding key codes and offers help on how you can find raw scan codes and translate them into key codes.