# Fix Alt modifier stuck after Alt-Tab on Windows \(\#52220\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/38270bc027a46671f680b09d06cd7a13a62bbc99)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 38270bc027a46671f680b09d06cd7a13a62bbc99

Requested commit: 38270bc027a46671f680b09d06cd7a13a62bbc99

Commit: 38270bc027a46671f680b09d06cd7a13a62bbc99

Tree: 23ae16e6ab1401aec6f370abd9b6d3c445e71dcd

Author: HuaGu-Dragon

Committer: GitHub

## Message

```
Fix Alt modifier stuck after Alt-Tab on Windows (#52220)

## Context

Fixes a bug on Windows where the Alt modifier key becomes stuck in the
pressed state after using Alt-Tab to switch away from and back to the
Zed application.

### Root Cause
In `crates/gpui_windows/src/events.rs`, when the window loses focus
during Alt-Tab, the WM_KEYUP event for the Alt key is never delivered to
the application. The pending modifier state in GPUI remains as
`alt=true`. When the window regains focus, there is no synchronization
point to reset this stale state.

## How to Review

In `handle_activate_msg()` (WM_ACTIVATE handler), when the window is
activated:
1. Reset the cached modifier tracking state (`last_reported_modifiers`
and `last_reported_capslock` set to `None`)
2. Query the actual current modifier state from Windows using
`GetKeyState()` APIs
3. Dispatch a `ModifiersChanged` event with the true state to
synchronize GPUI

## Self-Review Checklist

<!-- Check before requesting review: -->
- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [ ] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

I think it's difficult to add tests for this because it's
platform-dependent, but I recorded a video for comparison — sorry I only
have an anime‑style app to show the key presses.

<details>
  <summary>Video</summary>
  


https://github.com/user-attachments/assets/b545178c-b360-4e2b-8d60-d6f95a0b4b79



https://github.com/user-attachments/assets/bc4d41eb-6f42-4040-a588-0fc46c576db7


</details>

Closes #45485

Release Notes: 

- Fixed Alt modifier key stuck after Alt-Tab on Windows. Modifier state
is now synchronized when the window regains focus, ensuring correct key
interpretation after window switching.
```

## Parents

- [555326aea451fd7c8273e726d045e7baac6ef84c](https://git.cafe/gitcafe/zed/commit/555326aea451fd7c8273e726d045e7baac6ef84c?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/38270bc027a46671f680b09d06cd7a13a62bbc99?format=markdown)
