Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclusive access to HID device #100

Open
Chrissie-AI opened this issue Jul 22, 2022 · 3 comments
Open

Exclusive access to HID device #100

Chrissie-AI opened this issue Jul 22, 2022 · 3 comments

Comments

@Chrissie-AI
Copy link

I have a 6DOF input device (SpaceNavigator) which I'm using in a Three.js application for camera control. Connecting to, opening and processing of reportIds in the eventHandler of my application work as expected. Thanks for making the webhid API available available!

BUT ...

... apparently some other (default?) eventHandler also gets fired prior to mine. I was not able to suppress this via

	e.stopImmediatePropagation();
	e.preventDefault();

so the default event handling seems be happening before any of my code gets executed.

In my particular use case, the SpaceNavigator's puck actions which control Rx, Ry, Rz rotations seem to be mapped to the 2D mouse's X- and Y-movements and the scroll wheel. So these default actions interfere with my intended camera control for as long as the 2D mouse cursor is within my application window. If the 2D mouse cursor is in another window, that window reacts to the default event processing of the events fired by my SpaceNavigator, while my application window at the same time gets the "clean" and intended reactions only.

What I'd like to see is getting exclusive access to an HID device's events, maybe via a parameter in the device.open() call. Any chance to get this added to the API?

@nondebug
Copy link
Collaborator

nondebug commented Jul 22, 2022

I don't have any issue with exclusive access in principle but I'm not sure it's possible to implement it consistently across all platforms and devices.

There's an open issue on the signal11/hidapi repo requesting this feature:

Option to open hid device with exclusive access #302

The implementation in Chrome doesn't use hidapi but we would want similar results. I think currently you can't use hidapi to request exclusive access on Windows due to limitations at the platform level.

Windows makes certain HID interfaces exclusive or shared based on the collection usage:

https://docs.microsoft.com/en-us/windows-hardware/drivers/hid/hid-architecture#hid-clients-supported-in-windows

@Chrissie-AI
Copy link
Author

Matt, thanks for this speedy comment.

Obviously, I'd prefer consistent results across platforms, stationary or mobile, and across OSses also.

I'm constrained to using Chrome (for which I'm grateful), because not many Browsers do implement the webhid API. On a related note, the hid input controller I'm using (SpaceNavigator) is not easily available on a mobile device, so that's secondary on my priority list.

@stewartoallen
Copy link

I'm in the same boat with a 6DOF device (same vendor) where it is really important to be able obtain exclusive use of the device to prevent the HID layer from treating 3 of the axes as mouse input. In most cases, users with a 6DOF device have a mouse for typical mouse things and a space mouse for 3D nav and object manipulation. This is currently not possible with WebHID.

I recommend changing the open() method signature to open(options = {}) where exclusive:boolean is an option. If exclusivity is requested and not supported or denied by the OS, it can throw an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants