From a74ee6a73ad437725557b05a304041337bb2ff31 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 15 Aug 2018 03:12:19 +0200 Subject: Try to get headphone button events Try to set up a listener for headphone button events. Doesn't appear to work. The initialiser is called, but the delegate method doesn't appear to be. I'm not seeing any of those log messages. Followed an example from here: https://github.com/radiant-player/radiant-player-mac/pull/450/files Not sure what I'm doing wrong yet, but decided I should commit what I have since I can't figure it out right now. --- DomeKey/HeadphoneKey.h | 4 +++- DomeKey/HeadphoneKey.m | 24 ++++++++++++++++++++++++ DomeKey/main.m | 5 +++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/DomeKey/HeadphoneKey.h b/DomeKey/HeadphoneKey.h index 6bcca4a..16e74b2 100644 --- a/DomeKey/HeadphoneKey.h +++ b/DomeKey/HeadphoneKey.h @@ -9,6 +9,8 @@ #import #import -@interface HeadphoneKey : NSObject +@interface HeadphoneKey : NSObject { + NSArray *_mikeys; +} @end diff --git a/DomeKey/HeadphoneKey.m b/DomeKey/HeadphoneKey.m index af3b94c..c01d2c5 100644 --- a/DomeKey/HeadphoneKey.m +++ b/DomeKey/HeadphoneKey.m @@ -10,4 +10,28 @@ @implementation HeadphoneKey +- (instancetype)init +{ + self = [super init]; + if (self) { + _mikeys = [DDHidAppleMikey allMikeys]; + [_mikeys makeObjectsPerformSelector:@selector(setDelegate:) + withObject:self]; + [_mikeys makeObjectsPerformSelector:@selector(setListenInExclusiveMode:) + withObject:(id)kCFBooleanTrue]; + [_mikeys makeObjectsPerformSelector:@selector(startListening)]; + } + return self; +} + +- (void)ddhidAppleMikey:(DDHidAppleMikey *)mikey + press:(unsigned)usageId + upOrDown:(BOOL)upOrDown +{ + NSLog(@"Clicked"); + NSLog(@"%d", usageId); + NSLog(@"%@", mikey); + NSLog(@"%d", upOrDown); +} + @end diff --git a/DomeKey/main.m b/DomeKey/main.m index e0eea29..27df36e 100644 --- a/DomeKey/main.m +++ b/DomeKey/main.m @@ -7,11 +7,16 @@ // #import +#import "HeadphoneKey.h" int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... NSLog(@"Hello, World!"); + + HeadphoneKey *h = [[HeadphoneKey alloc] init]; + while (YES) { + } } return 0; } -- cgit v1.2.3