Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 677681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:03:58+00:00 2026-05-14T01:03:58+00:00

Some mac apps, like iTunes and Spotify, react to the play/pause/next/previous buttons on some

  • 0

Some mac apps, like iTunes and Spotify, react to the play/pause/next/previous buttons on some Apple keyboards.

Presumably they’re tapping into some sort of NSNotification, how can I do the same?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:03:58+00:00Added an answer on May 14, 2026 at 1:03 am

    I do this by subclassing NSApplication (and setting that class as the application class in my target’s info) with the following:

    #import <IOKit/hidsystem/ev_keymap.h>
    

    …

    - (void)mediaKeyEvent:(int)key state:(BOOL)state
    {
     switch (key)
     {
      // Play pressed
      case NX_KEYTYPE_PLAY:
       if (state == NO)
        [(TSAppController *)[self delegate] togglePlayPause:self];
       break;
    
      // FF pressed
      case NX_KEYTYPE_FAST:
       if (state == YES)
        [(TSAppController *)[self delegate] seekForward:self];
       break;
    
      // RW pressed
      case NX_KEYTYPE_REWIND:
       if (state == YES)
        [(TSAppController *)[self delegate] seekBack:self];
       break;
     }
    }
    
    - (void)sendEvent:(NSEvent *)event
    {
     // Catch media key events
     if ([event type] == NSSystemDefined && [event subtype] == NX_SUBTYPE_AUX_CONTROL_BUTTONS)
     {
      int keyCode = (([event data1] & 0xFFFF0000) >> 16);
      int keyFlags = ([event data1] & 0x0000FFFF);
      int keyState = (((keyFlags & 0xFF00) >> 8)) == 0xA;
    
      // Process the media key event and return
      [self mediaKeyEvent:keyCode state:keyState];
      return;
     }
    
     // Continue on to super
     [super sendEvent:event];
    }
    

    The “state” in -mediaKeyEvent:state: is for up/down. In my app it makes sense to only react to the play/pause key when it’s back up (done pressing), but I continuously react to RW/FF events while the key is down for seeking.

    I’d love to know of a better way to do this if it exists, though. Currently, unless the user disables these keys in the global keyboard shortcuts, it controls my app and iTunes. 🙂

    This code has been used quite awhile in my transcription app and works well (aside from the global keyboard shortcut issue above).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do apps like Apple's Remote app control mac applications and send data? is
My boss wants me to develop some apps and make them appear on the
I have been experimenting with a lot of web development apps like Drupal, Moodle,
I'm looking at making some mobile apps in my spare time and I want
It seems like there is a lot of online information regarding switching between views
I'm working on a project in Ruby right now that is essentially a web-app.
What's the simplest way of programatically checking whether or not a particular Windows machine
I am looking for a simple tutorial (framework?) that will explain me basic steps
Being a pretty experienced PHP developer, and having a fair knowledge of C (Wrote

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.