bevyengine / bevyengine/bevy

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

Open Beginner friendly
#25,483 0 comments 0 reactions 0 assignees View on GitHub
A-Input A-Windowing C-Bug S-Needs-Review
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## 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`
- Because of [legacy linux keyboard layout swap hotkey weirdness](https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config/-/work_items/122), with the above setting, `Key::GroupPrevious` is released instead of `Key::Alt`.
1. 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:
```rust
// 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.

Contributor guide

Open the contributing guide

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.