crossterm
crossterm copied to clipboard
AltGr keys produce alt and ctrl modifier on windows
Describe the bug This issue was first reported in https://github.com/helix-editor/helix/issues/7129 including a reprocutions case. I did some digging there (https://github.com/helix-editor/helix/issues/7129#issuecomment-1717771690) AltGr handling seems a mess on windows but I do think this may be a bug in crossterm. Disclaimer that i don't have a windows machine or a keyboard that uses altgr at hand myself so I didn't test this myself but the original reproduction case was confirmed by multiple people in helix and we don't do any processing of crossterm key events.
I cameup with the reproduction case below but I can't test it myself:
To Reproduce Steps to reproduce the behavior:
- Open windows terminal
- run the
event-read
exmaple - use a german keyboard layout and press
altgr-7
to type{
- Observe modifier
Alt | Ctrl
in the key event (with char{
)
Expected behavior
A key event for {
without modifier is emitted.
OS Windows
Terminal/Console Windows Terminal (stable and preview) and Git Bash (+winpty)
As far as I know that's how windows sends them https://github.com/microsoft/Terminal/blob/660d31ac522186e615ec243de2a434c273464828/src/terminal/input/terminalInput.cpp#L400-L419
I think it's a good idea to check what termwiz do here.
yeah I am aware, see my liked comment in the helix issue. But that is not really how applications are supposed to interpret it AFAIK (its some legacy stuff as always on windows).
The snippet you liked does exactly what i was suggesting: Removing the lctr and ralt modifiers in case they are pressed simultaneously. I am not really aware of windows terminal internals and why they are stripping it there but still sending it trough to the tui (perphaps that code is just for internal keymap handling).
Termwiz doesn't seem to handle this altough I am not sure. There seems to be some handling for it but at the wezterm layer rather than inside termwiz
this is how vim handles this:
https://github.com/vim/vim/blob/6ffcc58be32aa1b337bc839cfe173b68cfde7085/src/os_win32.c#L1266