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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
I do this by subclassing NSApplication (and setting that class as the application class in my target’s info) with the following:
…
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).