objective c - Make my Cocoa app respond to the keyboard play/pause key? -


is there way make app respond play/pause button on mac?

edit:

using suggested code,i console message:

could not connect action buttonpressed: target of class nsapplication

why be?

i accomplished in own application subclassing nsapplication (and setting app's principal class subclass). catches seek , play/pause keys , translates them specific actions in app delegate.

relevant lines:

#import <iokit/hidsystem/ev_keymap.h>  - (void)sendevent:(nsevent *)event {     // catch media key events     if ([event type] == nssystemdefined && [event subtype] == 8)     {         int keycode = (([event data1] & 0xffff0000) >> 16);         int keyflags = ([event data1] & 0x0000ffff);         int keystate = (((keyflags & 0xff00) >> 8)) == 0xa;          // process media key event , return         [self mediakeyevent:keycode state:keystate];         return;     }      // continue on super     [super sendevent:event]; }  - (void)mediakeyevent:(int)key state:(bool)state {     switch (key)     {         // play pressed         case nx_keytype_play:             if (state == no)                 [(tsappcontroller *)[self delegate] toggleplaypause:self];             break;          // rewind         case nx_keytype_fast:             if (state == yes)                 [(tsappcontroller *)[self delegate] seekforward:self];             break;          // previous         case nx_keytype_rewind:             if (state == yes)                 [(tsappcontroller *)[self delegate] seekback:self];             break;     } } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -