Unfocusing a window does not clear `ButtonInput<Key>`

Open Beginner friendly
#25,483 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
game-dev

Research direction

Read bevy_winit/system.rs and bevy_input/src/keyboard.rs, starting at check_keyboard_focus_lost and keyboard_input_system; compare the behavior with related issue #25041. Verify that losing window focus clears all cached ButtonInput state, including Alt, after the unusual key-release sequence described.

Written by the indexing model from the issue text.

Description

A-Input A-Windowing C-Bug S-Needs-Review

Bevy version and features

0.19.0, 0.19.1, main

[Optional] Relevant system information

Linux (with "Switching to another layout > Both Alts together" set)

What you did

  1. Press & Release Alt
  2. Click away from the bevy window
    • bevy should now clear all keyboard state, but it misses Key::Alt because KeyCode::Alt was already released

What went wrong

Bevy should clear its Key states when it loses keyboard focus, but it does not.

Additional information

check_keyboard_focus_lost in bevy_winit/system.rs should normally clear Key::Alt. It does not do so because KeyCode::Alt was already cleared by the normal key up event.

keyboard_input_system in bevy_input/src/keyboard.rs should also have caught this, but key_input.release_all() is missing:

// Release all cached input to avoid having stuck input when switching between windows in os
if !keyboard_focus_lost_reader.is_empty() {
    keycode_input.release_all();
    keyboard_focus_lost_reader.clear();
}

I believe this issue is strongly related to #25041.

Dominant language
Rust
Stars
48.3k
Forks
4.9k
Avg merge
3d 17h
Merged PRs (30d)
172

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.

More from bevyengine/bevy

All issues in bevyengine/bevy

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.