Created
May 27, 2011 21:07
-
-
Save danielwestendorf/996172 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyApplication < NSApplication | |
def sendEvent(event) | |
if event.type == NSSystemDefined && event.subtype == 8 #determine if one of the media keys was pressed | |
keyCode = (event.data1 & 0xFFFF0000) >> 16 | |
keyFlags = event.data1 & 0x0000FFFF | |
keyState = (keyFlags & 0xFF00) >> 8 == 0xA | |
mediaKeyPressed(keyCode) if keyState | |
super(nil) #don't passing anything on to super | |
else | |
super(event) #not what we were looking for, pass the event on to super. | |
end | |
end | |
def mediaKeyPressed(keyCode) | |
if keyCode == 20 #previous track key was pressed | |
NSNotificationCenter.defaultCenter.postNotificationName('MyApplicationPreviousTrack', object:nil) | |
elsif keyCode == 19 #next track key was pressed | |
NSNotificationCenter.defaultCenter.postNotificationName('MyApplicationNextTrack', object:nil) | |
elsif keyCode == 16 #play/pause key was pressed | |
NSNotificationCenter.defaultCenter.postNotificationName('MyApplicationPlayToggle', object:nil) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment