Skip to content

Commit

Permalink
Allow using navigation keys as fast-forward hotkey, forward more key …
Browse files Browse the repository at this point in the history
…presses to core
  • Loading branch information
Aurumaker72 committed Aug 16, 2023
1 parent 962397b commit 2181271
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion M64RPFW.Views.Avalonia/Controls/HotkeyButton.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ public KeyGesture CurrentHotkey
get => GetValue(CurrentHotkeyProperty);
set => SetValue(CurrentHotkeyProperty, value);
}

protected override void OnKeyDown(KeyEventArgs e)
{
// Button has to have been activated for this to work
if (Button?.IsChecked is null or false)
return;

// modifiers don't count
if (e.Key is Key.LeftCtrl or Key.RightCtrl or Key.LeftShift or Key.RightShift or Key.LeftAlt or Key.RightAlt
or Key.LWin or Key.RWin)
Expand Down
2 changes: 0 additions & 2 deletions M64RPFW.Views.Avalonia/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
Height="480"
Closed="Window_OnClosed"
SizeChanged="Window_OnSizeChanged"
KeyDown="Window_OnKeyDown"
KeyUp="Window_OnKeyUp"
Loaded="Window_OnLoaded"
x:CompileBindings="True"
x:DataType="vm:EmulatorViewModel">
Expand Down
8 changes: 5 additions & 3 deletions M64RPFW.Views.Avalonia/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public MainWindow()
DataContext = EmulatorViewModel.Instance;
}

// built-in key events won't work, since those get swallowed when the pressed key is a navigation key
AddHandler(KeyDownEvent, OnPreviewKeyDown, RoutingStrategies.Tunnel);
AddHandler(KeyUpEvent, OnPreviewKeyUp, RoutingStrategies.Tunnel);
}

// avalonia compiled binding resolver lives in another assembly, so these have to be public :(
Expand All @@ -55,7 +58,7 @@ private void Window_OnSizeChanged(object? sender, SizeChangedEventArgs e)

private KeyGesture FastForwardKeyGesture => KeyGesture.Parse(SettingsViewModel.Instance.FastForwardHotkey);

private void Window_OnKeyDown(object? sender, KeyEventArgs e)
private void OnPreviewKeyDown(object? sender, KeyEventArgs e)
{
if (FastForwardKeyGesture.Matches(e))
{
Expand All @@ -70,8 +73,7 @@ private void Window_OnKeyDown(object? sender, KeyEventArgs e)
var modifiers = SDLHelpers.ToSDLKeymod(e.KeyModifiers);
ViewModel.ForwardSDLKeyDown(scancode, modifiers);
}

private void Window_OnKeyUp(object? sender, KeyEventArgs e)
private void OnPreviewKeyUp(object? sender, KeyEventArgs e)
{
if (FastForwardKeyGesture.Matches(e))
{
Expand Down

0 comments on commit 2181271

Please sign in to comment.