I've been using the methods described here: http://weblog.rogueamoeba.com/2007/09/29/
and read this thread: Binding to Media keys on Apple keyboards under OSX 10.5
I've overridden the sendEvent class, and can detect media key input. The problem is that iTunes launches when the Play button is pressed. The above mentioned thread states that iTunes hooks into the event somewhere else (unknown), so there isn't a way to block it from getting the Play/Pause(F8) event.
As a workaround, I've been leaving Quicktime Player open with no file. However, on Mountain Lion, Quicktime closes itself after a certain period of inactivity apparently, thus rendering this workaround unviable.
I know applications such as Spotify and MPlayerX have been able to achieve this somehow. They appear to block the event completely, not just for iTunes.
More googling, I found this discussions.apple.com/thread/2122639?start=210&tstart=0 which tracks it down to the Remote Control Daemon making the calls via Applescript. There are some work arounds which removes the execution permission on the rcd daemon (requires sudo, has to be re-run anytime OSX is updated). nomitsu.com/contents/MMFix_src.tgz
Does anyone have any insight as to how they (MPlayerX, Spotify) have been able to do this is a less hacky way?
Thanks for any advice.
Open System Preferences. Choose keyboard. Ensure Use F1, F2, etc, keys… is unchecked. If already unchecked, check this option for a moment, then uncheck again.
Update the Keyboard Driver An outdated keyboard driver could stop the media keys from working. While Windows automatically installs any available updates, you can also install them manually. Right-click Start and select Device Manager. Extend the Keyboards menu.
Customise keyboard shortcuts On your Mac, choose Apple menu > System Preferences, click Keyboard , then click Shortcuts. In the list on the left, select a category, such as Mission Control or Spotlight. In the list on the right, select the tickbox next to the shortcut you want to change.
The Mac Media Key Forwarder utility makes the media keys actually useful instead of an erratic mess. It allows you to prioritise Spotify or Apple Music, despite whatever else is going on in the OS. This means the media keys are predictable, which is all I want in my buttons!
I found a pre-existing class that will do this: http://overooped.com/post/2593597587/mediakeys
Wow, that took some looking to find! Hope it helps someone else!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With