# Fix Right Alt key not working in keybindings on Windows \(\#40536\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 3d6722be9abf94af5680a3323b69a452154c55b2

Requested commit: 3d6722be9abf94af5680a3323b69a452154c55b2

Commit: 3d6722be9abf94af5680a3323b69a452154c55b2

Tree: 32c2e3e8596c3b4ce8c8a1d2bd137a356a96431f

Author: joel

Committer: GitHub

## Message

```
Fix Right Alt key not working in keybindings on Windows (#40536)

### Problem
On Windows, the right Alt key was not working in keybindings (e.g.,
`Ctrl+Right Alt+B`), while the left Alt key worked correctly. This was
due to overly aggressive AltGr detection that treated any `right Alt +
left Ctrl` combination as AltGr, even on US keyboards where AltGr
doesn't exist.

### Root Cause
Windows internally represents AltGr (Alt Graph) as `right Alt + left
Ctrl` pressed simultaneously. The previous implementation always
excluded this combination from being treated as regular modifier keys to
support international keyboards. However, this broke keybindings using
right Alt on US/UK keyboards where users expect right Alt to behave
identically to left Alt.

### Solution
Implemented keyboard layout-aware AltGr detection:

1. Added `uses_altgr()` method to `WindowsKeyboardLayout` that checks if
the current keyboard layout is known to use AltGr (German, French,
Spanish, Polish, etc.)
2. Modified `current_modifiers()` to only apply AltGr special handling
when the keyboard layout actually uses it
3. Added explicit checking for both `VK_LMENU` and `VK_RMENU` instead of
relying solely on the generic `VK_MENU`

### Behavior
- **US/UK keyboards**: Right Alt now works identically to left Alt in
keybindings. `Ctrl+Right Alt+B` triggers the same action as `Ctrl+Left
Alt+B`
- **International keyboards** (German, French, Spanish, etc.): AltGr
continues to work correctly for typing special characters and doesn't
trigger keybindings
- **All keyboards**: Both Alt keys are detected symmetrically, matching
the behavior of left/right Windows keys

### Testing
Manually tested on Windows with US keyboard layout:
-  `Ctrl+Left Alt+B` triggers keybinding
-  `Ctrl+Right Alt+B` triggers keybinding  
-  Both Alt keys work independently in keybindings


Release Notes:
- Fixed Right Alt key not working in keybindings on Windows
```

## Parents

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

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