rust-windowing / rust-windowing/winit

Use raw input instead of WM messages to detect physical key events

Open
#4,233 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

B - bug DS - win32
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):

  1. ✓ ↓LeftShift
  2. ✓ ↓RightShift (although it's marked as "repeat", but that might be a different bug (already mentioned) or maybe the cause is the same)
  3. X ↑RightShift
  4. ✓ ↑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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.