Hello!
So, diving through the docs I am kind of baffled as to what a good way to find the correct VirtualKeyCode for a given character would be.
I am trying to build very simple (dynamic) key-binding into my application. I am saving the state of the keyboard into in an keyboard_state: [bool; KEYBOARD_KEY_COUNT] and due to the ordering of the VirtualKeyCode e.g. VirtualKeyCode::W corresponds to 32.
But of course W as u8 translates to 87.
So if I read in W from the config, I will never be able to simply check the array by that Index.
I would very much like to avoid having to maintain another mapping table and am curious as well:
Am I missing something obvious here?
If you want to save and load keyboard mappings to/from config files, we provide serde support that can be enabled with the serde feature. That enables Serialize/Deserialize support for VirtualKeyCode and various other types which sounds like it should do what you want. However, outside of that we don't provide any officially-supported methods for converting u32s or chars to VirtualKeyCodes.
Thank you!
Although I was aware of the serde feature, I was curious if I was missing something.
With this approach (serializing via serde) the keybindings file is not as easily editable outside the application anymore, due to the fact that one needs to known the mapping to the appropriate VirtualKeyCode (Which is totally fine for most keys, but LAlt for example may strange instead of e.g. Left Alt)
(Another reason being that I tried to keep this part of the application untied to a 3rd party library)
I had merely hoped that I was missing something and could learn some awesome trick here! ;)
Be that as it may, I want to thank you for your time and also everyone involved for winit itself! It's a great library.
Most helpful comment
If you want to save and load keyboard mappings to/from config files, we provide
serdesupport that can be enabled with theserdefeature. That enablesSerialize/Deserializesupport forVirtualKeyCodeand various other types which sounds like it should do what you want. However, outside of that we don't provide any officially-supported methods for convertingu32s orchars toVirtualKeyCodes.