Skip to content

Commit

Permalink
Fix: Handle AltGr on Windows
Browse files Browse the repository at this point in the history
AltGr on windos sends a left control pressed followed by AltGr pressed
on both winit and Qt. On AltGr release it sends left control released
followed by AltGr released.

So unset left control on windows once AltGr is pressed to avoid treating
special characters entered via AltGr key combos to be treated as control
sequences -- leading to the input being ignored!

Also treat `Alt-Ctlr-X` as `AltGr-X` on windows.

Fixes: #2933
  • Loading branch information
hunger committed Jun 21, 2023
1 parent 18d5680 commit 54f988c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions internal/core/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ impl InternalKeyboardModifierState {
if let Some(key_code) = text.chars().next() {
match key_code {
key_codes::Alt => self.left_alt = pressed,
key_codes::AltGr => { /* fall through to special cases */ }
key_codes::Control => self.left_control = pressed,
key_codes::ControlR => self.right_control = pressed,
key_codes::Shift => self.left_shift = pressed,
Expand All @@ -193,10 +194,24 @@ impl InternalKeyboardModifierState {
key_codes::MetaR => self.right_meta = pressed,
_ => return None,
};

// Encoded keyboard modifiers must appear as individual key events. This could
// be relaxed by implementing a string split, but right now WindowEvent::KeyPressed
// holds only a single char.
debug_assert_eq!(key_code.len_utf8(), text.len());

// Special cases:
#[cfg(target_os = "windows")]
{
if key_code == key_codes::AltGr {
// Windows sends Ctrl followed by AltGr on AltGr. Disable the Ctrl again!
self.left_control = false;
} else if self.left_control && self.left_alt {
// Windows treats Ctrl-Alt as AltGr:
self.left_control = false;
self.left_alt = false;
}
}
}

Some(self)
Expand Down

0 comments on commit 54f988c

Please sign in to comment.