diff options
-rw-r--r-- | DomeKey/DKApplication.h | 2 | ||||
-rw-r--r-- | DomeKey/DKApplication.m | 38 | ||||
-rw-r--r-- | DomeKey/main.m | 3 |
3 files changed, 42 insertions, 1 deletions
diff --git a/DomeKey/DKApplication.h b/DomeKey/DKApplication.h index 6a92266..70ccd3a 100644 --- a/DomeKey/DKApplication.h +++ b/DomeKey/DKApplication.h @@ -10,4 +10,6 @@ @interface DKApplication : NSApplication +- (void)mediaKeyEvent:(int)key state:(BOOL)state repeat:(BOOL)repeat; + @end diff --git a/DomeKey/DKApplication.m b/DomeKey/DKApplication.m index 9449d06..4098ca7 100644 --- a/DomeKey/DKApplication.m +++ b/DomeKey/DKApplication.m @@ -10,4 +10,42 @@ @implementation DKApplication +// https://weblog.rogueamoeba.com/2007/09/29/ +- (void)sendEvent:(NSEvent *)theEvent +{ + if ([theEvent type] == NSSystemDefined && [theEvent subtype] == 8) { + int key_code = (([theEvent data1] & 0xFFFF0000) >> 16); + int key_flags = ([theEvent data1] & 0x0000FFFF); + int key_state = (((key_flags & 0xFF00) >> 8)) == 0xA; + int key_repeat = (key_flags & 0x1); + + [self mediaKeyEvent:key_code state:key_state repeat:key_repeat]; + } + + [super sendEvent:theEvent]; +} + +// https://weblog.rogueamoeba.com/2007/09/29/ +- (void)mediaKeyEvent:(int)key state:(BOOL)state repeat:(BOOL)repeat +{ + BOOL pressed_and_released = !state; + + if (pressed_and_released) { + switch (key) { + case NX_KEYTYPE_PLAY: + NSLog(@"Play"); + + break; + case NX_KEYTYPE_FAST: + NSLog(@"Fast"); + + break; + case NX_KEYTYPE_REWIND: + NSLog(@"Rewind"); + + break; + } + } +} + @end diff --git a/DomeKey/main.m b/DomeKey/main.m index aa2c66f..825e600 100644 --- a/DomeKey/main.m +++ b/DomeKey/main.m @@ -7,6 +7,7 @@ // #import <Foundation/Foundation.h> +#import "DKApplication.h" #import "AppDelegate.h" #import "Mappings.h" #import "dome_key_map.h" @@ -18,7 +19,7 @@ int main(int argc, const char * argv[]) { return [Mappings dispatchReload]; } else if (config->args.daemon) { @autoreleasepool { - [NSApplication sharedApplication]; + [DKApplication sharedApplication]; AppDelegate *app = [[AppDelegate alloc] init]; [NSApp setDelegate:app]; |