This question is concerning the code from this question: Detect headphone button presses in OS X
Their answer was marked correct, however I couldn\'t get their code
A test shows it isn't implemented as a keyboard anymore:
id array = [[DDHidDevice allDevices] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"productName == \"Apple Mikey HID Driver\""]];
DDHidDevice *mic = [array count] ? [array objectAtIndex:0] : nil;
// it isn't a keyboard
NSLog(@"%@", mic.primaryUsage);
assert(mic.usage==1 && mic.usagePage==12);
You can't treat it like a HIDKeyboard either (tried, it doesn't send key presses), nor a HIDMouse or HID Joystick.
I dug into the HIDQueue class and checked if the mikey fires any low level events and it does fire low level events! The queueCallbackFunction
is called for presses (if you don't filter the queue for specific events. To filter it, see initWithKeyboardEvents
in DDHidKeyboard.
Now all you have to do is map the low level events to the correct buttons and you are done. Maybe wrap it all in a nice class too. Here's a sample of the class and relevant code on GitHub.