rust-windowing / winit

Window handling library in pure Rust
https://docs.rs/winit/
Apache License 2.0
4.86k stars 909 forks source link

scan_code and virtual_key_code are swapped #2092

Closed Woyten closed 1 year ago

Woyten commented 2 years ago

https://github.com/rust-windowing/winit/blob/master/src/platform_impl/web/web_sys/event.rs considers event.key_code()/event.char_code() to be the scan_code of the KeyboardInput event and event.code() to be the virtual_key_code of the KeyboardInput event while it should be the other way around.

How to verify yourself: Use the links given below and a German keyboard layout and press the German z key

Demonstration of workaround in my personal project: https://github.com/Woyten/tune/commit/38b7ecd4841083bfb8d86440ee8d9fa4f73f52aa and https://github.com/Woyten/tune/commit/fcec2d38545ed0fdd76fd8a5b6c242095522f1ca

Woyten commented 2 years ago

@madsmtm I would like to contribute to winit by fixing this problem. Is that okay or is there some impediment like s.o. already working on it or an opposite opinion / vision regarding this topic?

madsmtm commented 2 years ago

I've no idea, the keyboard model is not something I've looked at at all.

See this meta issue: https://github.com/rust-windowing/winit/issues/1806, the fix may be present somewhere in those PRs already. Though if the fix is as simple as it sounds, your could try making a PR to fix it, though a big issue right now is that we don't have a WASM maintainer to approve it at the moment (see Testers and Contributors table), so not sure that would get you anywhere either.

maroider commented 2 years ago

The only sane keyboard input API on the web is fundamentally incompatible with winit's current keyboard API.

I unfortunately cannot give you an ETA on when #1888 (and thus a reasonable way of doing what you want to do) will get merged into the new-keyboard branch.

Woyten commented 2 years ago

@maroider What about an imperfect but less broken WASM implementation? I could do the following:

I know this is not a bullet-proof solution but the current implementation is broken in a way which prevents projects like Nannou from delivering a first-class WASM experience. The biggest impediment probably is the modifiers state not being handled correctly. As I said: I would invest some time to help making the implementation less broken.

kchibisov commented 1 year ago

Fixed on master.