Skip to content

Commit

Permalink
fix: Track modifiers throughout key sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Oct 5, 2024
1 parent 1ee9a7b commit 69a7287
Showing 1 changed file with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ public static async void PressKeySequence(string keys, UIElement element = null)
return;
}

VirtualKeyModifiers activeModifiers = VirtualKeyModifiers.None;

// In RS3, alt+shift is a hotkey and XAML will not be notified of the
// 'shift' key. We have the same behavior for the opposite sequence: if
// the sequence is shift+alt, XAML will not be notified of the 'alt' key.
Expand Down Expand Up @@ -164,7 +166,39 @@ public static async void PressKeySequence(string keys, UIElement element = null)
var key = keyInstruction.Substring(4, keyInstruction.Length - 4);
if (m_vKeyMapping.TryGetValue(key, out var vKey))
{
await RaiseOnElementDispatcherAsync(element, keyDownCodePos == 0 ? UIElement.KeyDownEvent : UIElement.KeyUpEvent, new KeyRoutedEventArgs(element, vKey, VirtualKeyModifiers.None));
await RaiseOnElementDispatcherAsync(element, keyDownCodePos == 0 ? UIElement.KeyDownEvent : UIElement.KeyUpEvent, new KeyRoutedEventArgs(element, vKey, activeModifiers));
}

// If modifiers were changed, update modifiers variable
if (keyDownCodePos == 0)
{
if (key == "shift")
{
activeModifiers |= VirtualKeyModifiers.Shift;
}
else if (key == "ctrl")
{
activeModifiers |= VirtualKeyModifiers.Control;
}
else if (key == "alt")
{
activeModifiers |= VirtualKeyModifiers.Menu;
}
}
else if (keyUpCodePos == 0)
{
if (key == "shift")
{
activeModifiers &= ~VirtualKeyModifiers.Shift;
}
else if (key == "ctrl")
{
activeModifiers &= ~VirtualKeyModifiers.Control;
}
else if (key == "alt")
{
activeModifiers &= ~VirtualKeyModifiers.Menu;
}
}
}
else
Expand Down

0 comments on commit 69a7287

Please sign in to comment.