-
Notifications
You must be signed in to change notification settings - Fork 127
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
Add support for scancode keyboard input #312
Add support for scancode keyboard input #312
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to add another example for physical keyboard mapping, since the virtual_dpad example aims to example how to solve a different problem.
Using the new QueryScanCode
may be confusing for new users.
@afonsolage I reverted the changes to the virtual_dpad example and created a new one. Please let me know if you think this works better :) |
I created a mini Bevy app to check which key has which scan code: https://github.com/TimJentzsch/bevy_scan_code_test It looks like the arrow key scan codes are different, I'll have to double check why |
Did you verify that this behaves well in WASM? I had some surprises there recently when using |
Good point, I didn't test that yet. |
Looks like the values are indeed different for WASM, I found a reference here: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode#value_of_keycode There might be some differences on WASM between the OS, which kinda sucks for us since we have the same compile target on WASM for all OS. Anyway, time to copy another batch of hex values... 🙃 |
@janhohenheim I noticed that for Foxtrot you sampled the scan codes by hand. Do you happen to have a MacOs device with Apple keyboard available for testing? |
Could the |
I would like that, but I'm fine to defer it to another PR. |
I'm using this branch in Foxtrot now to help you catch bugs and I found it to be broken on wasm: live demo. For reference, this is how I setup my |
Thanks @janhohenheim for reporting this issue! This was caused by a dumb copy/paste error which resulted in the macOS configuration being used on WASM.
|
Cool, I'll check in an hour 🙂 |
I think the last remaining part is figuring out why some of the Windows/Linux scan codes appear to be wrong. At least the ones prefixed by |
Okay, code quality is solid. Going to test this out on my Windows machine and see what I get. |
Windows data for you @TimJentzsch: https://gist.github.com/alice-i-cecile/bc86f697497a44228ab20ced8b463a3c |
…g-input-manager into 307-scancode-support
The Windows keycodes seem to match what I got. But it seems like Linux has different bindings, at least on my machine.
But I couldn't find this combination on the specs I found. |
@TimJentzsch I blindly copied values for Linux without testing them, so don't trust those too much 😉 |
I think I found the Linux values through this winit PR, it links to the Linux source directly: https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h From the few values I checked it seems to match up. |
That has to be the most trustworthy source you could find 😄 |
@alice-i-cecile Linux added, this should be ready to review now. |
This is as good as we're going to get for an initial impl: merging and shipping. |
Closes #307, closes #179.
This PR adds support for scan code keyboard input, i.e., using the key location instead of the logical key value.
This makes sense when you care about the physical location of the key rather than which letter it represents.
This is an important feature for games, as the classical WASD movement input should have keys that are closely together, in the triangle shape.
When a player uses the French AZERTY keyboard layout instead of the US QWERTY one, the ZQSD keys make more sense (which are on the same position as the WASD keys on the QWERTY layout).
You can now convert a
ScanCode
intoInputKind
to achieve this.Furthermore, I added a helper enum
QwertyKeyLocation
, which makes it easy to select the correct scan codes based on their keys on the QWERTY keyboard layout.The classical virtual dpad can now be defined like this:
TODO
QwertyScanCode
(mostly the Numpad keys).QwertyScanCode
which is selected based on thetarget_os
.Feedback Wanted
InputKind::Keyboard
but alsoInputKind::KeyLocation
.AlsoI renamed it toQwertyKeyLocation
can probably be improved, maybeQwertyScanCode
makes more sense here?QwertyScanCode
.QwertyScanCode
is appreciated, as it will be very hard to find errors here after merging.