I'm building a MacOS app using IOKit.
I'm encountering an issue where if Karabiner is running before I run my app, opening a HIDManager fails with kIOReturnExclusiveAccess
.
If I close Karabiner and run my app, the HIDManager opens successfully. I can then reopen karabiner and both apps function as normal.
This is a snippet of where in my code this is occurring.
let noreturn = IOHIDManagerOpen(manager, IOOptionBits(kIOHIDOptionsTypeNone));
if(noreturn == kIOReturnExclusiveAccess) {
print("FAILED");
}
I have originally posted this as an issue to the developer, but I'm not sure if it's me or them. Also, I saw that this previous issue went unacknowledged, so thought best to ask here also.
I am new to using IOKit with MacOS, and don't yet understand why this could occur.
Is anybody able to give me an understanding whether I should be doing something to work around this on my side? It seems tricky to deal with if another application is able to "hog" the HID interface.
Any help would be much appreciated.
Update
The developer answered my question on the GitHub issue I raised.
Karabiner-Elements open IOHIDDevice with kIOHIDOptionsTypeSeizeDevice in order to avoid hidd receives unmodified input events. It causes kIOReturnExclusiveAccess if other apps will open the devices.
As per the Apple documentation for kIOHIDOptionsTypeSeizeDevice
Used to open exclusive communication with the device. This will prevent the system and other clients from receiving events from the device.
Karabiner does this so that the system doesn't receive HID events before Karabiner has a chance to modify them.
If any one like myself needs a bit more of a primer on this, I found the technical notes for the HID Manager APIs super helpful.
At this point, I'm still figuring out best options around this.