aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-08-15 03:12:19 +0200
committerTeddy Wing2018-08-15 03:12:19 +0200
commita74ee6a73ad437725557b05a304041337bb2ff31 (patch)
tree738ca979837e327f5b579654025e5fd26dfa86f3
parent9dd1a71645f63501a5deb1276a7af26fbb9b0421 (diff)
downloadDomeKey-a74ee6a73ad437725557b05a304041337bb2ff31.tar.bz2
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.
-rw-r--r--DomeKey/HeadphoneKey.h4
-rw-r--r--DomeKey/HeadphoneKey.m24
-rw-r--r--DomeKey/main.m5
3 files changed, 32 insertions, 1 deletions
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 <Foundation/Foundation.h>
#import <DDHidLib/DDHidAppleMikey.h>
-@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 <Foundation/Foundation.h>
+#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;
}