rust-windowing / rust-windowing/winit
Use raw input instead of WM messages to detect physical key events
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 6.2k
- Forks
- 1.3k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 9
Description
Description
It seems that currently Winit on Windows relies entirely on window messages to detect key down/up events for its own event loop that dispatches WindowEvent::KeyboardInput.
However, this detection fails in some cases. For example (✓ marks winit correctly processing/dispatching physical key event, ✗ fails):
- ✓ ↓LeftShift
- ✓ ↓RightShift (although it's marked as "repeat", but that might be a different bug (already mentioned) or maybe the cause is the same)
- X ↑RightShift
- ✓ ↑LeftShift
Searching around this is identical to https://github.com/SFML/SFML/issues/1301, and the solution there was to use raw input events https://github.com/SFML/SFML/pull/1449/files
Brief testing by printing raw input events in handle_raw_input shows that yes, the 3rd ↑RightShift event IS detected with raw input even though it's hidden in the current WindowEvent::KeyboardInput
So maybe Winit should switch to RawInput comletely for physical keys? Since it also has the legacy WM_KEYDOWN/up messages, you wouldn't lose any information to construct Winit events? https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rawkeyboard
(note: this is about physical key events, not logical modifier state)
Windows version
Microsoft Windows [Version 10.0.26100.4061]
Winit version
git using this sample app (cargo run --example window)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Windows handle_raw_input path and the linked sample app, running cargo run --example window to reproduce the missing RightShift release. Compare raw input with the current keyboard event handling and consult the linked raw keyboard API reference. Done means physical key events, including the reported RightShift release, are dispatched reliably.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100