macOS: keys_down can get stuck if keys are released while main window title bar is clicked
- Dominant language
- Rust
- Stars
- 30.6k
- Forks
- 2.1k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 72
Description
**Describe the bug**
Not sure if this is an issue in egui or winit, since it seems quite specific to Mac window management events and I couldn’t reproduce this on other platforms. But it can be reproduced with a native macOS build of the egui demo app (I used latest main `87de733da`):
1. Press and hold a key, this generates key events and adds the key to `keys_down`.
2. Click the window title bar and keep it clicked. No key events are registered in `raw_input` events anymore.
3. Release the held key while the title bar is clicked. Since no key events are registered, you also don’t get a release event.
4. `keys_down` then keeps your previously pressed key forever.
5. You can only get out of this trap again if you remember that key and press and release it again when the title bar is not clicked. This will remove the key from `keys_down` upon the release event here: https://github.com/emilk/egui/blob/87de733da3083bda31344d7dcbd85e17183db65a/crates/egui/src/input_state/mod.rs#L313
Here’s a video showing that exact behavior with the input inspection UI in the demo app:
https://github.com/user-attachments/assets/cdd652fe-f686-479c-bcea-8fd8e1736ccb
I originally noticed this in my app, where I use key bindings for interaction and have a compact title bar with UI elements. This leads to a non-zero chance of „accidentally“ releasing a key while clicking something in the title bar area and then being stuck with some interaction (e.g. movement). This can be of course quite confusing as a user (it took me a while to understand & debug this 🙃).
https://github.com/user-attachments/assets/3dc11942-f8cf-43a4-86eb-821eca103089
**Workarounds?**
I didn’t find a good workaround yet. One hack would be to clear `keys_down` manually if no key events come for a specific time, but this could maybe generate other side effects.
**Expected behavior**
`keys_down` gets cleared also if a key is released while clicking the titlebar of macOS windows.
**Desktop (please complete the following information):**
- OS: macOS
- Version: Sequoia 15.5
**Additional context**
Somewhat related to: https://github.com/emilk/egui/issues/3653
Contributor guide
Research direction
Start with crates/egui/src/input_state/mod.rs around the referenced key-release handling, then reproduce the issue in the native macOS egui demo while clicking the title bar. Trace whether the missing release originates in egui or winit. Done means released keys no longer remain stuck in keys_down after title-bar interaction, with behavior checked on macOS.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- macos, rust
- Domain
- desktop-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100