Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 336
Jonah Braun Avatar asked Sep 22 '08 12:09

Jonah Braun


1 Answers

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
like image 124
Rhythmic Fistman Avatar answered Nov 02 '22 05:11

Rhythmic Fistman