Fix macOS Caps Lock capture in Avalonia keyboard driver

This commit is contained in:
Babib3l
2026-04-01 15:14:28 +02:00
parent 23b9a47d08
commit 70207cd374

View File

@@ -1,5 +1,6 @@
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Interactivity;
using Ryujinx.Ava.Common.Locale; using Ryujinx.Ava.Common.Locale;
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.Input; using Ryujinx.Input;
@@ -48,8 +49,11 @@ namespace Ryujinx.Ava.Input
_pressedKeyQueueLock = new(); _pressedKeyQueueLock = new();
_defaultMode = defaultMode; _defaultMode = defaultMode;
_control.KeyDown += OnKeyPress; // Use routed handlers so keys consumed earlier in the Avalonia pipeline
_control.KeyUp += OnKeyRelease; // can still be observed by the input driver. This is needed for keys like
// Caps Lock on macOS, which may not reach the plain CLR event path.
_control.AddHandler(InputElement.KeyDownEvent, OnKeyPress, RoutingStrategies.Tunnel, true);
_control.AddHandler(InputElement.KeyUpEvent, OnKeyRelease, RoutingStrategies.Tunnel, true);
_control.TextInput += Control_TextInput; _control.TextInput += Control_TextInput;
} }
@@ -91,8 +95,8 @@ namespace Ryujinx.Ava.Input
{ {
if (disposing) if (disposing)
{ {
_control.KeyDown -= OnKeyPress; _control.RemoveHandler(InputElement.KeyDownEvent, OnKeyPress);
_control.KeyUp -= OnKeyRelease; _control.RemoveHandler(InputElement.KeyUpEvent, OnKeyRelease);
_control.TextInput -= Control_TextInput; _control.TextInput -= Control_TextInput;
} }
} }