twitchyliquid64 / usbd-hid

MIT License
88 stars 37 forks source link

Add an enum for Keyboard Keycodes like there is for MediaKey and SystemControlKey #35

Closed TheButlah closed 1 year ago

TheButlah commented 2 years ago

Hi, I think it would be more straightforward of an API to have an enum for the the different keyboard scancodes. I am happy to contribute such an enum - I would just populate it with the contents of https://usb.org/sites/default/files/hut1_22.pdf#page=83 right?

haata commented 2 years ago

This is a somewhat complicated problem because what the labels are depend on the locale of the computer (yes you can just say that US is the default and the rest of the locales have to do their own lookups), but it's rather confusing.

The way I handle this is a bit different, where I have this library https://github.com/hid-io/layouts-rs that pulls in from a database of json files and constructs the lookups on demand. My use case is mainly for a compiler though and isn't directly used with usbd-hid.

I don't really see a good way of handling this directly with enums beyond a bunch of helper functions that can convert the enums to the appropriate locales.

haata commented 1 year ago

Should be resolved now at least for US keyboards (which is the default per https://usb.org/sites/default/files/hut1_3_0.pdf).