Skip to content

Commit

Permalink
refactor: Improve key modifier checks and AltGr detection (#1051)
Browse files Browse the repository at this point in the history
  • Loading branch information
gadfly3173 authored Mar 4, 2025
1 parent 96538b9 commit 25e6e26
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/Views/Launcher.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,19 @@ protected override void OnKeyDown(KeyEventArgs e)
// We should clear all unhandled key modifiers.
_unhandledModifiers = KeyModifiers.None;

// Check for AltGr (which is detected as Ctrl+Alt)
bool isAltGr = e.KeyModifiers.HasFlag(KeyModifiers.Control) &&
e.KeyModifiers.HasFlag(KeyModifiers.Alt);

// Skip hotkey processing if AltGr is pressed
if (isAltGr)
{
base.OnKeyDown(e);
return;
}

// Ctrl+Shift+P opens preference dialog (macOS use hotkeys in system menu bar)
if (!OperatingSystem.IsMacOS() && e.KeyModifiers == (KeyModifiers.Control | KeyModifiers.Shift) && e.Key == Key.P)
if (!OperatingSystem.IsMacOS() && e is { KeyModifiers: (KeyModifiers.Control | KeyModifiers.Shift), Key: Key.P })
{
App.OpenDialog(new Preferences());
e.Handled = true;
Expand Down Expand Up @@ -243,13 +254,13 @@ protected override void OnKeyDown(KeyEventArgs e)
{
_unhandledModifiers = e.KeyModifiers;

if (!_unhandledModifiers.HasFlag(KeyModifiers.Alt) && (e.Key == Key.LeftAlt || e.Key == Key.RightAlt))
if (!_unhandledModifiers.HasFlag(KeyModifiers.Alt) && e.Key is Key.LeftAlt or Key.RightAlt)
_unhandledModifiers |= KeyModifiers.Alt;

if (!_unhandledModifiers.HasFlag(KeyModifiers.Control) && (e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl))
if (!_unhandledModifiers.HasFlag(KeyModifiers.Control) && e.Key is Key.LeftCtrl or Key.RightCtrl)
_unhandledModifiers |= KeyModifiers.Control;

if (!_unhandledModifiers.HasFlag(KeyModifiers.Shift) && (e.Key == Key.LeftShift || e.Key == Key.RightShift))
if (!_unhandledModifiers.HasFlag(KeyModifiers.Shift) && e.Key is Key.LeftShift or Key.RightShift)
_unhandledModifiers |= KeyModifiers.Shift;
}
}
Expand Down

0 comments on commit 25e6e26

Please sign in to comment.