Skip to content

Commit 25e6e26

Browse files
authored
refactor: Improve key modifier checks and AltGr detection (#1051)
1 parent 96538b9 commit 25e6e26

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/Views/Launcher.axaml.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,19 @@ protected override void OnKeyDown(KeyEventArgs e)
112112
// We should clear all unhandled key modifiers.
113113
_unhandledModifiers = KeyModifiers.None;
114114

115+
// Check for AltGr (which is detected as Ctrl+Alt)
116+
bool isAltGr = e.KeyModifiers.HasFlag(KeyModifiers.Control) &&
117+
e.KeyModifiers.HasFlag(KeyModifiers.Alt);
118+
119+
// Skip hotkey processing if AltGr is pressed
120+
if (isAltGr)
121+
{
122+
base.OnKeyDown(e);
123+
return;
124+
}
125+
115126
// Ctrl+Shift+P opens preference dialog (macOS use hotkeys in system menu bar)
116-
if (!OperatingSystem.IsMacOS() && e.KeyModifiers == (KeyModifiers.Control | KeyModifiers.Shift) && e.Key == Key.P)
127+
if (!OperatingSystem.IsMacOS() && e is { KeyModifiers: (KeyModifiers.Control | KeyModifiers.Shift), Key: Key.P })
117128
{
118129
App.OpenDialog(new Preferences());
119130
e.Handled = true;
@@ -243,13 +254,13 @@ protected override void OnKeyDown(KeyEventArgs e)
243254
{
244255
_unhandledModifiers = e.KeyModifiers;
245256

246-
if (!_unhandledModifiers.HasFlag(KeyModifiers.Alt) && (e.Key == Key.LeftAlt || e.Key == Key.RightAlt))
257+
if (!_unhandledModifiers.HasFlag(KeyModifiers.Alt) && e.Key is Key.LeftAlt or Key.RightAlt)
247258
_unhandledModifiers |= KeyModifiers.Alt;
248259

249-
if (!_unhandledModifiers.HasFlag(KeyModifiers.Control) && (e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl))
260+
if (!_unhandledModifiers.HasFlag(KeyModifiers.Control) && e.Key is Key.LeftCtrl or Key.RightCtrl)
250261
_unhandledModifiers |= KeyModifiers.Control;
251262

252-
if (!_unhandledModifiers.HasFlag(KeyModifiers.Shift) && (e.Key == Key.LeftShift || e.Key == Key.RightShift))
263+
if (!_unhandledModifiers.HasFlag(KeyModifiers.Shift) && e.Key is Key.LeftShift or Key.RightShift)
253264
_unhandledModifiers |= KeyModifiers.Shift;
254265
}
255266
}

0 commit comments

Comments
 (0)