winit
winit copied to clipboard
Provide support to know what type of device was added
Discussed in https://github.com/rust-windowing/winit/discussions/2497
Originally posted by Angelo13C September 19, 2022 Guys, I am using winit to create a window and everything works fine.
Now I need to manage input in my application, and winit fires the DeviceEvent::Added when a new device is added, so that's great. The problem is: how do I know what type of device was added? Was it a mouse, a keyboard..??
And is there any way to get extra info about it (something like how many buttons the mouse has)?
I received as an answer from other people that a device may send many types of event, but even knowing that a device could be a keyboard or a mouse, rather than knowing nothing would be useful.. (exposing an HID device struct?)
This would be a great solution: https://github.com/rust-windowing/winit/discussions/2497#discussioncomment-3684567
This would be useful for a custom input system made on top of winit (like Unity's new input system)
I think that to add a feature like this, it is better to expose an HID structure, first because there are many different devices (https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf) and second because it should be possible to implement it on all platforms.
For example, in Windows we can only know for sure if the device is a keyboard or a mouse, otherwise we have to expose the HID structure, see : https://github.com/rust-windowing/winit/blob/76f158d3102aeb54e6c1c2ce2fd34dbe6b0daab1/src/platform_impl/windows/raw_input.rs#L56-L60
Well that would already be awesome!
Hi @Angelo13C, after reviewing the code I discovered that Winit already has the functionality you are looking for, but it is not visible in the documentation. Basically, you use persisten_identifier() on a device identifier and "this returns an identifier that persistently references that specific device".
And with that identifier, you can retrieve more information about the device.
By the way, @madsmtm, I'm new to the Winit organization and I'm wondering how the Winit documentation is updated?
Hi @killianc3
Can you please show me where the persistent_identifier function is? Because the only ones I see are Windows platform specific, and that's a bit of a problem (I think it should be known in every platform what the HID is)
(this is the search I made: https://github.com/rust-windowing/winit/search?q=persistent_identifier)
Oh yes, I forgot to mention that this is a Windows specific feature, I'm sorry. After checking, you're right, other systems don't implement this kind of feature.
By the way, @madsmtm, I'm new to the Winit organization and I'm wondering how the Winit documentation is updated?
I'm not sure what you're asking? It's written as part of the code, and then uploaded to docs.rs once a new version is published.
Ok, I ask because I didn't understand why on the docs I built the cagro docs there are features that are not present on the online docs. But now it's clear to me, thanks.