You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Composite hid device that's also a keyboard on Mac OS X #344
I have an issue with implementing a HID-based protocol for a BLE device that is also a keyboard an getting it to work under Mac OS X. My guess is that the operating system refuses to give us access to the hid device due to the fact of it also being a keyboard. When using USB the solution is pretty simple, just use a different endpoint for the custom protocol, but for BLE we can only have a single HOG endpoint. I'm wondering if there is, or if it would be possible to implement, a way for hidapi to not try to grab the whole device, but instead just grab the reports of the usages we're interested in.
the operating system refuses to give us access to the hid device due to the fact of it also being a keyboard
That is true. No workaround is possible on SW/HIDAPI side. The way HID driver is implemented on macOS, a device with multiple usage_pages/usages is represented as a single undividable device.
When using USB the solution is pretty simple, just use a different endpoint for the custom protocol
Agree, that's what I'd do.
but for BLE we can only have a single HOG endpoint
This is a bit suprising, I've imagined that something similar should be possible.
But I have never worked with BLE devices so I cannot be sure or give any hints.
Looking into the issue a bit more it seems like we can grab the device if we run the application under sudo and if we allow "Input Monitoring" for the application under Privacy/Input Monitoring in the security & privacy settings.
The next issue is that this causes the keypresses of the device to not be handled by the operating system. I think this might be because of the kIOHIDOptionsTypeSeizeDevice flag when opening the device. I haven't been able to investigate that further for now, but I'm planning to see what happens without that flag set.
And this seems to work beautifully and not need root permissions anymore. So just changing that flag to zero makes us able to open those devices from normal user applications if the Input Monitoring setting is enabled for our application.
That is something that has been on our place for some time. If we remove that flag by default with a new update - that will break backward compatibility for programs that may rely on it. I'm currently thinking on the alternative approach.
Would it break backwards compatibility though? The hidraw backend on Linux doesn't allow exclusive access afaik. I don't know how the situation is on windows, but shouldn't hidapi cater to the "lowest common denominator"?.
If that is an issue another option is to expose an open_nonexclusive() function, but I'm not sure that would be needed.
It is not about what it should or shouldn't do. HIDAPI has been opening the device on macOS exclusively since the very first version. And even if it is beeter not to do this way by default, by changing the default, we break the backward compativility of the programs that are already using HIDAPI on macOS and rely on such behavior explicitly or implicitly.
I understand what you mean, I’m just saying that since other platforms hidapi support do not open the devices with exclusive access the probability of a Mac OS X application using hidapi depending on that behaviour would be pretty low. The reason being that the main reason of using hidapi on Mac OS X would be portability.
That being said I’m not advocating for changing the default, you surely know a lot more about hidapis users than I do, but I would be grateful for being able to open the device in non-exclusive access mode (without having to resort to patching hidapi).
Activity
Youw commentedon Oct 13, 2021
That is true. No workaround is possible on SW/HIDAPI side. The way HID driver is implemented on macOS, a device with multiple usage_pages/usages is represented as a single undividable device.
Agree, that's what I'd do.
This is a bit suprising, I've imagined that something similar should be possible.
But I have never worked with BLE devices so I cannot be sure or give any hints.
dnaq commentedon Oct 14, 2021
Looking into the issue a bit more it seems like we can grab the device if we run the application under sudo and if we allow "Input Monitoring" for the application under Privacy/Input Monitoring in the security & privacy settings.
The next issue is that this causes the keypresses of the device to not be handled by the operating system. I think this might be because of the
kIOHIDOptionsTypeSeizeDeviceflag when opening the device. I haven't been able to investigate that further for now, but I'm planning to see what happens without that flag set.dnaq commentedon Oct 14, 2021
And this seems to work beautifully and not need root permissions anymore. So just changing that flag to zero makes us able to open those devices from normal user applications if the Input Monitoring setting is enabled for our application.
Youw commentedon Oct 14, 2021
That is something that has been on our place for some time. If we remove that flag by default with a new update - that will break backward compatibility for programs that may rely on it. I'm currently thinking on the alternative approach.
dnaq commentedon Oct 14, 2021
Would it break backwards compatibility though? The hidraw backend on Linux doesn't allow exclusive access afaik. I don't know how the situation is on windows, but shouldn't hidapi cater to the "lowest common denominator"?.
If that is an issue another option is to expose an
open_nonexclusive()function, but I'm not sure that would be needed.Youw commentedon Oct 14, 2021
It is not about what it should or shouldn't do. HIDAPI has been opening the device on macOS exclusively since the very first version. And even if it is beeter not to do this way by default, by changing the default, we break the backward compativility of the programs that are already using HIDAPI on macOS and rely on such behavior explicitly or implicitly.
dnaq commentedon Oct 14, 2021
I understand what you mean, I’m just saying that since other platforms hidapi support do not open the devices with exclusive access the probability of a Mac OS X application using hidapi depending on that behaviour would be pretty low. The reason being that the main reason of using hidapi on Mac OS X would be portability.
That being said I’m not advocating for changing the default, you surely know a lot more about hidapis users than I do, but I would be grateful for being able to open the device in non-exclusive access mode (without having to resort to patching hidapi).
Youw commentedon Oct 15, 2021
You're not the only one:
mcuee commentedon Oct 19, 2021
Is it possible to add a new API (or new API option) to open in non-exclusive access mode?
Youw commentedon Oct 20, 2021
@mcuee please check my suggestion from some time ago: https://github.com/orgs/libusb/teams/hidapi/discussions/4 (this link is available only for HIDAPI team members).
darwin: add option to open device in non-exclusive mode (#397)