From 84f3ce2ca5e71a6dda820baeb4cf53ef588ce4a7 Mon Sep 17 00:00:00 2001 From: Babib3l Date: Wed, 18 Mar 2026 21:10:28 +0100 Subject: [PATCH] Update keyboard localisation refactor snapshot --- .../Keyboard/StandardKeyboardInputConfig.cs | 2 +- .../Hid/KeyboardKeyExtensions.cs | 19 +++ .../Configuration/Hid/PhysicalKey.cs | 142 ++++++++++++++++++ src/Ryujinx.Input.SDL3/SDL3Keyboard.cs | 52 +++---- src/Ryujinx.Input.SDL3/SDLKeyboardDriver.cs | 7 +- src/Ryujinx.Input/HLE/NpadController.cs | 5 +- src/Ryujinx.Input/IKeyboardModeDriver.cs | 7 + src/Ryujinx.Input/KeyboardInputMode.cs | 8 + src/Ryujinx.Input/PhysicalKeyExtensions.cs | 14 ++ src/Ryujinx/Headless/HeadlessRyujinx.Init.cs | 66 ++++---- src/Ryujinx/Input/AvaloniaKeyboard.cs | 60 ++++---- src/Ryujinx/Input/AvaloniaKeyboardDriver.cs | 118 ++++++++++----- .../ConfigurationState.Migration.cs | 66 ++++---- .../Configuration/ConfigurationState.cs | 66 ++++---- .../Helpers/Converters/KeyValueConverter.cs | 3 + .../UI/Helpers/PhysicalKeyLabelHelper.cs | 131 ++++++++++++++++ .../UI/Models/Input/KeyboardInputConfig.cs | 64 ++++---- .../UI/Models/Input/StickVisualizer.cs | 16 +- .../UI/ViewModels/Input/InputViewModel.cs | 68 ++++----- .../UI/Views/Input/KeyboardInputView.axaml.cs | 114 +++++++------- .../Settings/SettingsHotkeysView.axaml.cs | 2 +- src/Ryujinx/UI/Windows/MainWindow.axaml.cs | 3 +- 22 files changed, 708 insertions(+), 325 deletions(-) create mode 100644 src/Ryujinx.Common/Configuration/Hid/KeyboardKeyExtensions.cs create mode 100644 src/Ryujinx.Common/Configuration/Hid/PhysicalKey.cs create mode 100644 src/Ryujinx.Input/IKeyboardModeDriver.cs create mode 100644 src/Ryujinx.Input/KeyboardInputMode.cs create mode 100644 src/Ryujinx.Input/PhysicalKeyExtensions.cs create mode 100644 src/Ryujinx/UI/Helpers/PhysicalKeyLabelHelper.cs diff --git a/src/Ryujinx.Common/Configuration/Hid/Keyboard/StandardKeyboardInputConfig.cs b/src/Ryujinx.Common/Configuration/Hid/Keyboard/StandardKeyboardInputConfig.cs index 1e8b188e7..548b0762c 100644 --- a/src/Ryujinx.Common/Configuration/Hid/Keyboard/StandardKeyboardInputConfig.cs +++ b/src/Ryujinx.Common/Configuration/Hid/Keyboard/StandardKeyboardInputConfig.cs @@ -1,4 +1,4 @@ namespace Ryujinx.Common.Configuration.Hid.Keyboard { - public class StandardKeyboardInputConfig : GenericKeyboardInputConfig { } + public class StandardKeyboardInputConfig : GenericKeyboardInputConfig { } } diff --git a/src/Ryujinx.Common/Configuration/Hid/KeyboardKeyExtensions.cs b/src/Ryujinx.Common/Configuration/Hid/KeyboardKeyExtensions.cs new file mode 100644 index 000000000..f6bf50987 --- /dev/null +++ b/src/Ryujinx.Common/Configuration/Hid/KeyboardKeyExtensions.cs @@ -0,0 +1,19 @@ +namespace Ryujinx.Common.Configuration.Hid +{ + public static class KeyboardKeyExtensions + { + public static Key ToKey(this PhysicalKey key) + { + return key is >= PhysicalKey.Unknown and < PhysicalKey.Count + ? (Key)(int)key + : Key.Unknown; + } + + public static PhysicalKey ToPhysicalKey(this Key key) + { + return key is >= Key.Unknown and < Key.Count + ? (PhysicalKey)(int)key + : PhysicalKey.Unknown; + } + } +} diff --git a/src/Ryujinx.Common/Configuration/Hid/PhysicalKey.cs b/src/Ryujinx.Common/Configuration/Hid/PhysicalKey.cs new file mode 100644 index 000000000..c9cc1b8cd --- /dev/null +++ b/src/Ryujinx.Common/Configuration/Hid/PhysicalKey.cs @@ -0,0 +1,142 @@ +using System.Text.Json.Serialization; + +namespace Ryujinx.Common.Configuration.Hid +{ + [JsonConverter(typeof(JsonStringEnumConverter))] + public enum PhysicalKey + { + Unknown, + ShiftLeft, + ShiftRight, + ControlLeft, + ControlRight, + AltLeft, + AltRight, + WinLeft, + WinRight, + Menu, + F1, + F2, + F3, + F4, + F5, + F6, + F7, + F8, + F9, + F10, + F11, + F12, + F13, + F14, + F15, + F16, + F17, + F18, + F19, + F20, + F21, + F22, + F23, + F24, + F25, + F26, + F27, + F28, + F29, + F30, + F31, + F32, + F33, + F34, + F35, + Up, + Down, + Left, + Right, + Enter, + Escape, + Space, + Tab, + BackSpace, + Insert, + Delete, + PageUp, + PageDown, + Home, + End, + CapsLock, + ScrollLock, + PrintScreen, + Pause, + NumLock, + Clear, + Keypad0, + Keypad1, + Keypad2, + Keypad3, + Keypad4, + Keypad5, + Keypad6, + Keypad7, + Keypad8, + Keypad9, + KeypadDivide, + KeypadMultiply, + KeypadSubtract, + KeypadAdd, + KeypadDecimal, + KeypadEnter, + A, + B, + C, + D, + E, + F, + G, + H, + I, + J, + K, + L, + M, + N, + O, + P, + Q, + R, + S, + T, + U, + V, + W, + X, + Y, + Z, + Number0, + Number1, + Number2, + Number3, + Number4, + Number5, + Number6, + Number7, + Number8, + Number9, + Tilde, + Grave, + Minus, + Plus, + BracketLeft, + BracketRight, + Semicolon, + Quote, + Comma, + Period, + Slash, + BackSlash, + Unbound, + + Count, + } +} diff --git a/src/Ryujinx.Input.SDL3/SDL3Keyboard.cs b/src/Ryujinx.Input.SDL3/SDL3Keyboard.cs index f5da11a19..8dec2ba35 100644 --- a/src/Ryujinx.Input.SDL3/SDL3Keyboard.cs +++ b/src/Ryujinx.Input.SDL3/SDL3Keyboard.cs @@ -9,7 +9,7 @@ using System.Threading; using SDL; using static SDL.SDL3; -using ConfigKey = Ryujinx.Common.Configuration.Hid.Key; +using ConfigPhysicalKey = Ryujinx.Common.Configuration.Hid.PhysicalKey; namespace Ryujinx.Input.SDL3 { @@ -264,27 +264,27 @@ namespace Ryujinx.Input.SDL3 return value * ConvertRate; } - private static (short, short) GetStickValues(ref KeyboardStateSnapshot snapshot, JoyconConfigKeyboardStick stickConfig) + private static (short, short) GetStickValues(ref KeyboardStateSnapshot snapshot, JoyconConfigKeyboardStick stickConfig) { short stickX = 0; short stickY = 0; - if (snapshot.IsPressed((Key)stickConfig.StickUp)) + if (snapshot.IsPressed(stickConfig.StickUp.ToInputKey())) { stickY += 1; } - if (snapshot.IsPressed((Key)stickConfig.StickDown)) + if (snapshot.IsPressed(stickConfig.StickDown.ToInputKey())) { stickY -= 1; } - if (snapshot.IsPressed((Key)stickConfig.StickRight)) + if (snapshot.IsPressed(stickConfig.StickRight.ToInputKey())) { stickX += 1; } - if (snapshot.IsPressed((Key)stickConfig.StickLeft)) + if (snapshot.IsPressed(stickConfig.StickLeft.ToInputKey())) { stickX -= 1; } @@ -361,28 +361,28 @@ namespace Ryujinx.Input.SDL3 _buttonsUserMapping.Clear(); // Then configure left joycon - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.LeftStick, (Key)_configuration.LeftJoyconStick.StickButton)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadUp, (Key)_configuration.LeftJoycon.DpadUp)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadDown, (Key)_configuration.LeftJoycon.DpadDown)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadLeft, (Key)_configuration.LeftJoycon.DpadLeft)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadRight, (Key)_configuration.LeftJoycon.DpadRight)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.Minus, (Key)_configuration.LeftJoycon.ButtonMinus)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.LeftShoulder, (Key)_configuration.LeftJoycon.ButtonL)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.LeftTrigger, (Key)_configuration.LeftJoycon.ButtonZl)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleRightTrigger0, (Key)_configuration.LeftJoycon.ButtonSr)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleLeftTrigger0, (Key)_configuration.LeftJoycon.ButtonSl)); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.LeftStick, _configuration.LeftJoyconStick.StickButton.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadUp, _configuration.LeftJoycon.DpadUp.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadDown, _configuration.LeftJoycon.DpadDown.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadLeft, _configuration.LeftJoycon.DpadLeft.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadRight, _configuration.LeftJoycon.DpadRight.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.Minus, _configuration.LeftJoycon.ButtonMinus.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.LeftShoulder, _configuration.LeftJoycon.ButtonL.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.LeftTrigger, _configuration.LeftJoycon.ButtonZl.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleRightTrigger0, _configuration.LeftJoycon.ButtonSr.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleLeftTrigger0, _configuration.LeftJoycon.ButtonSl.ToInputKey())); // Finally configure right joycon - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.RightStick, (Key)_configuration.RightJoyconStick.StickButton)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.A, (Key)_configuration.RightJoycon.ButtonA)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.B, (Key)_configuration.RightJoycon.ButtonB)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.X, (Key)_configuration.RightJoycon.ButtonX)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.Y, (Key)_configuration.RightJoycon.ButtonY)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.Plus, (Key)_configuration.RightJoycon.ButtonPlus)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.RightShoulder, (Key)_configuration.RightJoycon.ButtonR)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.RightTrigger, (Key)_configuration.RightJoycon.ButtonZr)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleRightTrigger1, (Key)_configuration.RightJoycon.ButtonSr)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleLeftTrigger1, (Key)_configuration.RightJoycon.ButtonSl)); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.RightStick, _configuration.RightJoyconStick.StickButton.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.A, _configuration.RightJoycon.ButtonA.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.B, _configuration.RightJoycon.ButtonB.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.X, _configuration.RightJoycon.ButtonX.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.Y, _configuration.RightJoycon.ButtonY.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.Plus, _configuration.RightJoycon.ButtonPlus.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.RightShoulder, _configuration.RightJoycon.ButtonR.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.RightTrigger, _configuration.RightJoycon.ButtonZr.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleRightTrigger1, _configuration.RightJoycon.ButtonSr.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleLeftTrigger1, _configuration.RightJoycon.ButtonSl.ToInputKey())); } } diff --git a/src/Ryujinx.Input.SDL3/SDLKeyboardDriver.cs b/src/Ryujinx.Input.SDL3/SDLKeyboardDriver.cs index cd2a067be..c401ab947 100644 --- a/src/Ryujinx.Input.SDL3/SDLKeyboardDriver.cs +++ b/src/Ryujinx.Input.SDL3/SDLKeyboardDriver.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; namespace Ryujinx.Input.SDL3 { - public class SDL3KeyboardDriver : IGamepadDriver + public class SDL3KeyboardDriver : IKeyboardModeDriver { public SDL3KeyboardDriver() { @@ -44,6 +44,11 @@ namespace Ryujinx.Input.SDL3 } public IGamepad GetGamepad(string id) + { + return GetKeyboard(id, KeyboardInputMode.Semantic); + } + + public IKeyboard GetKeyboard(string id, KeyboardInputMode mode) { if (!_keyboardIdentifers[0].Equals(id)) { diff --git a/src/Ryujinx.Input/HLE/NpadController.cs b/src/Ryujinx.Input/HLE/NpadController.cs index 84f9e89ab..732319107 100644 --- a/src/Ryujinx.Input/HLE/NpadController.cs +++ b/src/Ryujinx.Input/HLE/NpadController.cs @@ -2,6 +2,7 @@ using Ryujinx.Common; using Ryujinx.Common.Configuration.Hid; using Ryujinx.Common.Configuration.Hid.Controller; using Ryujinx.Common.Configuration.Hid.Controller.Motion; +using Ryujinx.Common.Configuration.Hid.Keyboard; using Ryujinx.Common.Logging; using Ryujinx.HLE.HOS.Services.Hid; using System; @@ -234,7 +235,9 @@ namespace Ryujinx.Input.HLE _gamepad?.Dispose(); Id = config.Id; - _gamepad = GamepadDriver.GetGamepad(Id); + _gamepad = config is StandardKeyboardInputConfig && GamepadDriver is IKeyboardModeDriver keyboardModeDriver + ? keyboardModeDriver.GetKeyboard(Id, KeyboardInputMode.Physical) + : GamepadDriver.GetGamepad(Id); UpdateUserConfiguration(config); diff --git a/src/Ryujinx.Input/IKeyboardModeDriver.cs b/src/Ryujinx.Input/IKeyboardModeDriver.cs new file mode 100644 index 000000000..62a835eb6 --- /dev/null +++ b/src/Ryujinx.Input/IKeyboardModeDriver.cs @@ -0,0 +1,7 @@ +namespace Ryujinx.Input +{ + public interface IKeyboardModeDriver : IGamepadDriver + { + IKeyboard GetKeyboard(string id, KeyboardInputMode mode); + } +} diff --git a/src/Ryujinx.Input/KeyboardInputMode.cs b/src/Ryujinx.Input/KeyboardInputMode.cs new file mode 100644 index 000000000..a46f3760d --- /dev/null +++ b/src/Ryujinx.Input/KeyboardInputMode.cs @@ -0,0 +1,8 @@ +namespace Ryujinx.Input +{ + public enum KeyboardInputMode + { + Semantic, + Physical, + } +} diff --git a/src/Ryujinx.Input/PhysicalKeyExtensions.cs b/src/Ryujinx.Input/PhysicalKeyExtensions.cs new file mode 100644 index 000000000..f2359d0d8 --- /dev/null +++ b/src/Ryujinx.Input/PhysicalKeyExtensions.cs @@ -0,0 +1,14 @@ +using ConfigPhysicalKey = Ryujinx.Common.Configuration.Hid.PhysicalKey; + +namespace Ryujinx.Input +{ + public static class PhysicalKeyExtensions + { + public static Key ToInputKey(this ConfigPhysicalKey key) + { + return key is >= ConfigPhysicalKey.Unknown and < ConfigPhysicalKey.Count + ? (Key)(int)key + : Key.Unknown; + } + } +} diff --git a/src/Ryujinx/Headless/HeadlessRyujinx.Init.cs b/src/Ryujinx/Headless/HeadlessRyujinx.Init.cs index af61b7b63..722da6637 100644 --- a/src/Ryujinx/Headless/HeadlessRyujinx.Init.cs +++ b/src/Ryujinx/Headless/HeadlessRyujinx.Init.cs @@ -24,7 +24,7 @@ using System.Text.Json; using System.Threading.Tasks; using ConfigGamepadInputId = Ryujinx.Common.Configuration.Hid.Controller.GamepadInputId; using ConfigStickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId; -using Key = Ryujinx.Common.Configuration.Hid.Key; +using PhysicalKey = Ryujinx.Common.Configuration.Hid.PhysicalKey; namespace Ryujinx.Headless { @@ -105,48 +105,48 @@ namespace Ryujinx.Headless Backend = InputBackendType.WindowKeyboard, Id = null, ControllerType = ControllerType.JoyconPair, - LeftJoycon = new LeftJoyconCommonConfig + LeftJoycon = new LeftJoyconCommonConfig { - DpadUp = Key.Up, - DpadDown = Key.Down, - DpadLeft = Key.Left, - DpadRight = Key.Right, - ButtonMinus = Key.Minus, - ButtonL = Key.E, - ButtonZl = Key.Q, - ButtonSl = Key.Unbound, - ButtonSr = Key.Unbound, + DpadUp = PhysicalKey.Up, + DpadDown = PhysicalKey.Down, + DpadLeft = PhysicalKey.Left, + DpadRight = PhysicalKey.Right, + ButtonMinus = PhysicalKey.Minus, + ButtonL = PhysicalKey.E, + ButtonZl = PhysicalKey.Q, + ButtonSl = PhysicalKey.Unbound, + ButtonSr = PhysicalKey.Unbound, }, - LeftJoyconStick = new JoyconConfigKeyboardStick + LeftJoyconStick = new JoyconConfigKeyboardStick { - StickUp = Key.W, - StickDown = Key.S, - StickLeft = Key.A, - StickRight = Key.D, - StickButton = Key.F, + StickUp = PhysicalKey.W, + StickDown = PhysicalKey.S, + StickLeft = PhysicalKey.A, + StickRight = PhysicalKey.D, + StickButton = PhysicalKey.F, }, - RightJoycon = new RightJoyconCommonConfig + RightJoycon = new RightJoyconCommonConfig { - ButtonA = Key.Z, - ButtonB = Key.X, - ButtonX = Key.C, - ButtonY = Key.V, - ButtonPlus = Key.Plus, - ButtonR = Key.U, - ButtonZr = Key.O, - ButtonSl = Key.Unbound, - ButtonSr = Key.Unbound, + ButtonA = PhysicalKey.Z, + ButtonB = PhysicalKey.X, + ButtonX = PhysicalKey.C, + ButtonY = PhysicalKey.V, + ButtonPlus = PhysicalKey.Plus, + ButtonR = PhysicalKey.U, + ButtonZr = PhysicalKey.O, + ButtonSl = PhysicalKey.Unbound, + ButtonSr = PhysicalKey.Unbound, }, - RightJoyconStick = new JoyconConfigKeyboardStick + RightJoyconStick = new JoyconConfigKeyboardStick { - StickUp = Key.I, - StickDown = Key.K, - StickLeft = Key.J, - StickRight = Key.L, - StickButton = Key.H, + StickUp = PhysicalKey.I, + StickDown = PhysicalKey.K, + StickLeft = PhysicalKey.J, + StickRight = PhysicalKey.L, + StickButton = PhysicalKey.H, }, }; } diff --git a/src/Ryujinx/Input/AvaloniaKeyboard.cs b/src/Ryujinx/Input/AvaloniaKeyboard.cs index fe7ec2670..0c18918c4 100644 --- a/src/Ryujinx/Input/AvaloniaKeyboard.cs +++ b/src/Ryujinx/Input/AvaloniaKeyboard.cs @@ -6,7 +6,7 @@ using System; using System.Collections.Generic; using System.Numerics; using System.Threading; -using ConfigKey = Ryujinx.Common.Configuration.Hid.Key; +using ConfigPhysicalKey = Ryujinx.Common.Configuration.Hid.PhysicalKey; using Key = Ryujinx.Input.Key; namespace Ryujinx.Ava.Input @@ -15,6 +15,7 @@ namespace Ryujinx.Ava.Input { private readonly List _buttonsUserMapping; private readonly AvaloniaKeyboardDriver _driver; + private readonly KeyboardInputMode _mode; private StandardKeyboardInputConfig _configuration; private uint _ledValue; @@ -32,11 +33,12 @@ namespace Ryujinx.Ava.Input public readonly Key From = from; } - public AvaloniaKeyboard(AvaloniaKeyboardDriver driver, string id, string name) + public AvaloniaKeyboard(AvaloniaKeyboardDriver driver, string id, string name, KeyboardInputMode mode) { _buttonsUserMapping = []; _driver = driver; + _mode = mode; Id = id; Name = name; } @@ -101,7 +103,7 @@ namespace Ryujinx.Ava.Input { try { - return _driver.IsPressed(key); + return _driver.IsPressed(key, _mode); } catch { @@ -119,28 +121,28 @@ namespace Ryujinx.Ava.Input #pragma warning disable IDE0055 // Disable formatting // Left JoyCon - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.LeftStick, (Key)_configuration.LeftJoyconStick.StickButton)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadUp, (Key)_configuration.LeftJoycon.DpadUp)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadDown, (Key)_configuration.LeftJoycon.DpadDown)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadLeft, (Key)_configuration.LeftJoycon.DpadLeft)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadRight, (Key)_configuration.LeftJoycon.DpadRight)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.Minus, (Key)_configuration.LeftJoycon.ButtonMinus)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.LeftShoulder, (Key)_configuration.LeftJoycon.ButtonL)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.LeftTrigger, (Key)_configuration.LeftJoycon.ButtonZl)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleRightTrigger0, (Key)_configuration.LeftJoycon.ButtonSr)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleLeftTrigger0, (Key)_configuration.LeftJoycon.ButtonSl)); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.LeftStick, _configuration.LeftJoyconStick.StickButton.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadUp, _configuration.LeftJoycon.DpadUp.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadDown, _configuration.LeftJoycon.DpadDown.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadLeft, _configuration.LeftJoycon.DpadLeft.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadRight, _configuration.LeftJoycon.DpadRight.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.Minus, _configuration.LeftJoycon.ButtonMinus.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.LeftShoulder, _configuration.LeftJoycon.ButtonL.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.LeftTrigger, _configuration.LeftJoycon.ButtonZl.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleRightTrigger0, _configuration.LeftJoycon.ButtonSr.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleLeftTrigger0, _configuration.LeftJoycon.ButtonSl.ToInputKey())); // Right JoyCon - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.RightStick, (Key)_configuration.RightJoyconStick.StickButton)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.A, (Key)_configuration.RightJoycon.ButtonA)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.B, (Key)_configuration.RightJoycon.ButtonB)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.X, (Key)_configuration.RightJoycon.ButtonX)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.Y, (Key)_configuration.RightJoycon.ButtonY)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.Plus, (Key)_configuration.RightJoycon.ButtonPlus)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.RightShoulder, (Key)_configuration.RightJoycon.ButtonR)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.RightTrigger, (Key)_configuration.RightJoycon.ButtonZr)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleRightTrigger1, (Key)_configuration.RightJoycon.ButtonSr)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleLeftTrigger1, (Key)_configuration.RightJoycon.ButtonSl)); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.RightStick, _configuration.RightJoyconStick.StickButton.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.A, _configuration.RightJoycon.ButtonA.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.B, _configuration.RightJoycon.ButtonB.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.X, _configuration.RightJoycon.ButtonX.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.Y, _configuration.RightJoycon.ButtonY.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.Plus, _configuration.RightJoycon.ButtonPlus.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.RightShoulder, _configuration.RightJoycon.ButtonR.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.RightTrigger, _configuration.RightJoycon.ButtonZr.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleRightTrigger1, _configuration.RightJoycon.ButtonSr.ToInputKey())); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleLeftTrigger1, _configuration.RightJoycon.ButtonSl.ToInputKey())); #pragma warning restore IDE0055 } } @@ -172,27 +174,27 @@ namespace Ryujinx.Ava.Input return value * ConvertRate; } - private static (short, short) GetStickValues(ref KeyboardStateSnapshot snapshot, JoyconConfigKeyboardStick stickConfig) + private static (short, short) GetStickValues(ref KeyboardStateSnapshot snapshot, JoyconConfigKeyboardStick stickConfig) { short stickX = 0; short stickY = 0; - if (snapshot.IsPressed((Key)stickConfig.StickUp)) + if (snapshot.IsPressed(stickConfig.StickUp.ToInputKey())) { stickY += 1; } - if (snapshot.IsPressed((Key)stickConfig.StickDown)) + if (snapshot.IsPressed(stickConfig.StickDown.ToInputKey())) { stickY -= 1; } - if (snapshot.IsPressed((Key)stickConfig.StickRight)) + if (snapshot.IsPressed(stickConfig.StickRight.ToInputKey())) { stickX += 1; } - if (snapshot.IsPressed((Key)stickConfig.StickLeft)) + if (snapshot.IsPressed(stickConfig.StickLeft.ToInputKey())) { stickX -= 1; } @@ -206,7 +208,7 @@ namespace Ryujinx.Ava.Input public void Clear() { - _driver?.Clear(); + _driver?.Clear(_mode); } public void Dispose() { } diff --git a/src/Ryujinx/Input/AvaloniaKeyboardDriver.cs b/src/Ryujinx/Input/AvaloniaKeyboardDriver.cs index c7a5bd395..f68d1cfb5 100644 --- a/src/Ryujinx/Input/AvaloniaKeyboardDriver.cs +++ b/src/Ryujinx/Input/AvaloniaKeyboardDriver.cs @@ -8,11 +8,13 @@ using Key = Ryujinx.Input.Key; namespace Ryujinx.Ava.Input { - internal class AvaloniaKeyboardDriver : IGamepadDriver + internal class AvaloniaKeyboardDriver : IKeyboardModeDriver { private static readonly string[] _keyboardIdentifers = ["0"]; private readonly Control _control; - private readonly Dictionary _pressedKeys; + private readonly Dictionary _semanticPressedKeys; + private readonly Dictionary _physicalPressedKeys; + private readonly KeyboardInputMode _defaultMode; public event EventHandler KeyPressed; public event EventHandler KeyRelease; @@ -21,10 +23,12 @@ namespace Ryujinx.Ava.Input public string DriverName => "AvaloniaKeyboardDriver"; public ReadOnlySpan GamepadsIds => _keyboardIdentifers; - public AvaloniaKeyboardDriver(Control control) + public AvaloniaKeyboardDriver(Control control, KeyboardInputMode defaultMode = KeyboardInputMode.Semantic) { _control = control; - _pressedKeys = []; + _semanticPressedKeys = []; + _physicalPressedKeys = []; + _defaultMode = defaultMode; _control.KeyDown += OnKeyPress; _control.KeyUp += OnKeyRelease; @@ -49,13 +53,18 @@ namespace Ryujinx.Ava.Input } public IGamepad GetGamepad(string id) + { + return GetKeyboard(id, _defaultMode); + } + + public IKeyboard GetKeyboard(string id, KeyboardInputMode mode) { if (!_keyboardIdentifers[0].Equals(id)) { return null; } - return new AvaloniaKeyboard(this, _keyboardIdentifers[0], LocaleManager.Instance[LocaleKeys.KeyboardLayout_AllKeyboards]); + return new AvaloniaKeyboard(this, _keyboardIdentifers[0], LocaleManager.Instance[LocaleKeys.KeyboardLayout_AllKeyboards], mode); } public IEnumerable GetGamepads() => [GetGamepad("0")]; @@ -66,63 +75,98 @@ namespace Ryujinx.Ava.Input { _control.KeyDown -= OnKeyPress; _control.KeyUp -= OnKeyRelease; + _control.TextInput -= Control_TextInput; } } protected void OnKeyPress(object sender, KeyEventArgs args) { - Key key = AvaloniaKeyboardMappingHelper.ToInputKey(args.PhysicalKey, args.Key); - - if (key != Key.Unknown) - { - if (_pressedKeys.TryGetValue(key, out int count)) - { - _pressedKeys[key] = count + 1; - } - else - { - _pressedKeys[key] = 1; - } - } + UpdateKeyState(_semanticPressedKeys, GetInputKey(args, KeyboardInputMode.Semantic), true); + UpdateKeyState(_physicalPressedKeys, GetInputKey(args, KeyboardInputMode.Physical), true); KeyPressed?.Invoke(this, args); } protected void OnKeyRelease(object sender, KeyEventArgs args) { - Key key = AvaloniaKeyboardMappingHelper.ToInputKey(args.PhysicalKey, args.Key); - - if (key != Key.Unknown) - { - if (_pressedKeys.TryGetValue(key, out int count)) - { - if (count <= 1) - { - _pressedKeys.Remove(key); - } - else - { - _pressedKeys[key] = count - 1; - } - } - } + UpdateKeyState(_semanticPressedKeys, GetInputKey(args, KeyboardInputMode.Semantic), false); + UpdateKeyState(_physicalPressedKeys, GetInputKey(args, KeyboardInputMode.Physical), false); KeyRelease?.Invoke(this, args); } - internal bool IsPressed(Key key) + internal bool IsPressed(Key key, KeyboardInputMode mode) { if (key is Key.Unbound or Key.Unknown) { return false; } - return _pressedKeys.ContainsKey(key); + return GetPressedKeys(mode).ContainsKey(key); + } + + internal void Clear(KeyboardInputMode mode) + { + GetPressedKeys(mode).Clear(); } public void Clear() { - _pressedKeys.Clear(); + _semanticPressedKeys.Clear(); + _physicalPressedKeys.Clear(); + } + + private Dictionary GetPressedKeys(KeyboardInputMode mode) + { + return mode == KeyboardInputMode.Physical ? _physicalPressedKeys : _semanticPressedKeys; + } + + private static void UpdateKeyState(Dictionary pressedKeys, Key key, bool isPressed) + { + if (key is Key.Unknown or Key.Unbound) + { + return; + } + + if (isPressed) + { + if (pressedKeys.TryGetValue(key, out int count)) + { + pressedKeys[key] = count + 1; + } + else + { + pressedKeys[key] = 1; + } + + return; + } + + if (pressedKeys.TryGetValue(key, out int currentCount)) + { + if (currentCount <= 1) + { + pressedKeys.Remove(key); + } + else + { + pressedKeys[key] = currentCount - 1; + } + } + } + + private static Key GetInputKey(KeyEventArgs args, KeyboardInputMode mode) + { + if (mode == KeyboardInputMode.Physical) + { + Key physicalKey = AvaloniaKeyboardMappingHelper.ToInputKey(args.PhysicalKey); + + return physicalKey != Key.Unknown + ? physicalKey + : AvaloniaKeyboardMappingHelper.ToInputKey(args.Key); + } + + return AvaloniaKeyboardMappingHelper.ToInputKey(args.PhysicalKey, args.Key); } public void Dispose() diff --git a/src/Ryujinx/Systems/Configuration/ConfigurationState.Migration.cs b/src/Ryujinx/Systems/Configuration/ConfigurationState.Migration.cs index 163b7e98f..aad6d1119 100644 --- a/src/Ryujinx/Systems/Configuration/ConfigurationState.Migration.cs +++ b/src/Ryujinx/Systems/Configuration/ConfigurationState.Migration.cs @@ -13,6 +13,8 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using Key = Ryujinx.Common.Configuration.Hid.Key; +using PhysicalKey = Ryujinx.Common.Configuration.Hid.PhysicalKey; using RyuLogger = Ryujinx.Common.Logging.Logger; namespace Ryujinx.Ava.Systems.Configuration @@ -269,45 +271,45 @@ namespace Ryujinx.Ava.Systems.Configuration Id = "0", PlayerIndex = PlayerIndex.Player1, ControllerType = ControllerType.ProController, - LeftJoycon = new LeftJoyconCommonConfig + LeftJoycon = new LeftJoyconCommonConfig { - DpadUp = Key.Up, - DpadDown = Key.Down, - DpadLeft = Key.Left, - DpadRight = Key.Right, - ButtonMinus = Key.Minus, - ButtonL = Key.E, - ButtonZl = Key.Q, - ButtonSl = Key.Unbound, - ButtonSr = Key.Unbound, + DpadUp = PhysicalKey.Up, + DpadDown = PhysicalKey.Down, + DpadLeft = PhysicalKey.Left, + DpadRight = PhysicalKey.Right, + ButtonMinus = PhysicalKey.Minus, + ButtonL = PhysicalKey.E, + ButtonZl = PhysicalKey.Q, + ButtonSl = PhysicalKey.Unbound, + ButtonSr = PhysicalKey.Unbound, }, - LeftJoyconStick = new JoyconConfigKeyboardStick + LeftJoyconStick = new JoyconConfigKeyboardStick { - StickUp = Key.W, - StickDown = Key.S, - StickLeft = Key.A, - StickRight = Key.D, - StickButton = Key.F, + StickUp = PhysicalKey.W, + StickDown = PhysicalKey.S, + StickLeft = PhysicalKey.A, + StickRight = PhysicalKey.D, + StickButton = PhysicalKey.F, }, - RightJoycon = new RightJoyconCommonConfig + RightJoycon = new RightJoyconCommonConfig { - ButtonA = Key.Z, - ButtonB = Key.X, - ButtonX = Key.C, - ButtonY = Key.V, - ButtonPlus = Key.Plus, - ButtonR = Key.U, - ButtonZr = Key.O, - ButtonSl = Key.Unbound, - ButtonSr = Key.Unbound, + ButtonA = PhysicalKey.Z, + ButtonB = PhysicalKey.X, + ButtonX = PhysicalKey.C, + ButtonY = PhysicalKey.V, + ButtonPlus = PhysicalKey.Plus, + ButtonR = PhysicalKey.U, + ButtonZr = PhysicalKey.O, + ButtonSl = PhysicalKey.Unbound, + ButtonSr = PhysicalKey.Unbound, }, - RightJoyconStick = new JoyconConfigKeyboardStick + RightJoyconStick = new JoyconConfigKeyboardStick { - StickUp = Key.I, - StickDown = Key.K, - StickLeft = Key.J, - StickRight = Key.L, - StickButton = Key.H, + StickUp = PhysicalKey.I, + StickDown = PhysicalKey.K, + StickLeft = PhysicalKey.J, + StickRight = PhysicalKey.L, + StickButton = PhysicalKey.H, }, } ]; diff --git a/src/Ryujinx/Systems/Configuration/ConfigurationState.cs b/src/Ryujinx/Systems/Configuration/ConfigurationState.cs index 0e2f6aaec..7cb1143ac 100644 --- a/src/Ryujinx/Systems/Configuration/ConfigurationState.cs +++ b/src/Ryujinx/Systems/Configuration/ConfigurationState.cs @@ -8,6 +8,8 @@ using Ryujinx.Graphics.Vulkan; using Ryujinx.HLE; using System; using System.Linq; +using Key = Ryujinx.Common.Configuration.Hid.Key; +using PhysicalKey = Ryujinx.Common.Configuration.Hid.PhysicalKey; namespace Ryujinx.Ava.Systems.Configuration { @@ -285,45 +287,45 @@ namespace Ryujinx.Ava.Systems.Configuration Name = "Keyboard", PlayerIndex = PlayerIndex.Player1, ControllerType = ControllerType.ProController, - LeftJoycon = new LeftJoyconCommonConfig + LeftJoycon = new LeftJoyconCommonConfig { - DpadUp = Key.Up, - DpadDown = Key.Down, - DpadLeft = Key.Left, - DpadRight = Key.Right, - ButtonMinus = Key.Minus, - ButtonL = Key.E, - ButtonZl = Key.Q, - ButtonSl = Key.Unbound, - ButtonSr = Key.Unbound, + DpadUp = PhysicalKey.Up, + DpadDown = PhysicalKey.Down, + DpadLeft = PhysicalKey.Left, + DpadRight = PhysicalKey.Right, + ButtonMinus = PhysicalKey.Minus, + ButtonL = PhysicalKey.E, + ButtonZl = PhysicalKey.Q, + ButtonSl = PhysicalKey.Unbound, + ButtonSr = PhysicalKey.Unbound, }, - LeftJoyconStick = new JoyconConfigKeyboardStick + LeftJoyconStick = new JoyconConfigKeyboardStick { - StickUp = Key.W, - StickDown = Key.S, - StickLeft = Key.A, - StickRight = Key.D, - StickButton = Key.F, + StickUp = PhysicalKey.W, + StickDown = PhysicalKey.S, + StickLeft = PhysicalKey.A, + StickRight = PhysicalKey.D, + StickButton = PhysicalKey.F, }, - RightJoycon = new RightJoyconCommonConfig + RightJoycon = new RightJoyconCommonConfig { - ButtonA = Key.Z, - ButtonB = Key.X, - ButtonX = Key.C, - ButtonY = Key.V, - ButtonPlus = Key.Plus, - ButtonR = Key.U, - ButtonZr = Key.O, - ButtonSl = Key.Unbound, - ButtonSr = Key.Unbound, + ButtonA = PhysicalKey.Z, + ButtonB = PhysicalKey.X, + ButtonX = PhysicalKey.C, + ButtonY = PhysicalKey.V, + ButtonPlus = PhysicalKey.Plus, + ButtonR = PhysicalKey.U, + ButtonZr = PhysicalKey.O, + ButtonSl = PhysicalKey.Unbound, + ButtonSr = PhysicalKey.Unbound, }, - RightJoyconStick = new JoyconConfigKeyboardStick + RightJoyconStick = new JoyconConfigKeyboardStick { - StickUp = Key.I, - StickDown = Key.K, - StickLeft = Key.J, - StickRight = Key.L, - StickButton = Key.H, + StickUp = PhysicalKey.I, + StickDown = PhysicalKey.K, + StickLeft = PhysicalKey.J, + StickRight = PhysicalKey.L, + StickButton = PhysicalKey.H, }, } ]; diff --git a/src/Ryujinx/UI/Helpers/Converters/KeyValueConverter.cs b/src/Ryujinx/UI/Helpers/Converters/KeyValueConverter.cs index 05ec55a4b..87c60edd4 100644 --- a/src/Ryujinx/UI/Helpers/Converters/KeyValueConverter.cs +++ b/src/Ryujinx/UI/Helpers/Converters/KeyValueConverter.cs @@ -151,6 +151,9 @@ namespace Ryujinx.Ava.UI.Helpers keyString = key.ToString(); } + break; + case PhysicalKey physicalKey: + keyString = PhysicalKeyLabelHelper.GetString(physicalKey); break; case GamepadInputId gamepadInputId: if (_gamepadInputIdMap.TryGetValue(gamepadInputId, out localeKey)) diff --git a/src/Ryujinx/UI/Helpers/PhysicalKeyLabelHelper.cs b/src/Ryujinx/UI/Helpers/PhysicalKeyLabelHelper.cs new file mode 100644 index 000000000..a3f437457 --- /dev/null +++ b/src/Ryujinx/UI/Helpers/PhysicalKeyLabelHelper.cs @@ -0,0 +1,131 @@ +using Avalonia.Input; +using Ryujinx.Ava.Common.Locale; +using Ryujinx.Ava.Input; +using Ryujinx.Common.Configuration.Hid; +using System; +using System.Collections.Generic; +using AvaPhysicalKey = Avalonia.Input.PhysicalKey; +using ConfigPhysicalKey = Ryujinx.Common.Configuration.Hid.PhysicalKey; +using InputKey = Ryujinx.Input.Key; + +namespace Ryujinx.Ava.UI.Helpers +{ + internal static class PhysicalKeyLabelHelper + { + private static readonly Dictionary _localizedKeysMap = new() + { + [ConfigPhysicalKey.Unknown] = LocaleKeys.KeyboardLayout_KeyUnknown, + [ConfigPhysicalKey.ShiftLeft] = LocaleKeys.KeyboardLayout_KeyShiftLeft, + [ConfigPhysicalKey.ShiftRight] = LocaleKeys.KeyboardLayout_KeyShiftRight, + [ConfigPhysicalKey.ControlLeft] = LocaleKeys.KeyboardLayout_KeyControlLeft, + [ConfigPhysicalKey.ControlRight] = LocaleKeys.KeyboardLayout_KeyControlRight, + [ConfigPhysicalKey.AltLeft] = LocaleKeys.KeyboardLayout_KeyAltLeft, + [ConfigPhysicalKey.AltRight] = LocaleKeys.KeyboardLayout_KeyAltRight, + [ConfigPhysicalKey.WinLeft] = LocaleKeys.KeyboardLayout_KeyWinLeft, + [ConfigPhysicalKey.WinRight] = LocaleKeys.KeyboardLayout_KeyWinRight, + [ConfigPhysicalKey.Up] = LocaleKeys.KeyboardLayout_KeyUp, + [ConfigPhysicalKey.Down] = LocaleKeys.KeyboardLayout_KeyDown, + [ConfigPhysicalKey.Left] = LocaleKeys.KeyboardLayout_KeyLeft, + [ConfigPhysicalKey.Right] = LocaleKeys.KeyboardLayout_KeyRight, + [ConfigPhysicalKey.Enter] = LocaleKeys.KeyboardLayout_KeyEnter, + [ConfigPhysicalKey.Escape] = LocaleKeys.KeyboardLayout_KeyEscape, + [ConfigPhysicalKey.Space] = LocaleKeys.KeyboardLayout_KeySpace, + [ConfigPhysicalKey.Tab] = LocaleKeys.KeyboardLayout_KeyTab, + [ConfigPhysicalKey.BackSpace] = LocaleKeys.KeyboardLayout_KeyBackSpace, + [ConfigPhysicalKey.Insert] = LocaleKeys.KeyboardLayout_KeyInsert, + [ConfigPhysicalKey.Delete] = LocaleKeys.KeyboardLayout_KeyDelete, + [ConfigPhysicalKey.PageUp] = LocaleKeys.KeyboardLayout_KeyPageUp, + [ConfigPhysicalKey.PageDown] = LocaleKeys.KeyboardLayout_KeyPageDown, + [ConfigPhysicalKey.Home] = LocaleKeys.KeyboardLayout_KeyHome, + [ConfigPhysicalKey.End] = LocaleKeys.KeyboardLayout_KeyEnd, + [ConfigPhysicalKey.CapsLock] = LocaleKeys.KeyboardLayout_KeyCapsLock, + [ConfigPhysicalKey.ScrollLock] = LocaleKeys.KeyboardLayout_KeyScrollLock, + [ConfigPhysicalKey.PrintScreen] = LocaleKeys.KeyboardLayout_KeyPrintScreen, + [ConfigPhysicalKey.Pause] = LocaleKeys.KeyboardLayout_KeyPause, + [ConfigPhysicalKey.NumLock] = LocaleKeys.KeyboardLayout_KeyNumLock, + [ConfigPhysicalKey.Clear] = LocaleKeys.KeyboardLayout_KeyClear, + [ConfigPhysicalKey.Keypad0] = LocaleKeys.KeyboardLayout_KeyKeypad0, + [ConfigPhysicalKey.Keypad1] = LocaleKeys.KeyboardLayout_KeyKeypad1, + [ConfigPhysicalKey.Keypad2] = LocaleKeys.KeyboardLayout_KeyKeypad2, + [ConfigPhysicalKey.Keypad3] = LocaleKeys.KeyboardLayout_KeyKeypad3, + [ConfigPhysicalKey.Keypad4] = LocaleKeys.KeyboardLayout_KeyKeypad4, + [ConfigPhysicalKey.Keypad5] = LocaleKeys.KeyboardLayout_KeyKeypad5, + [ConfigPhysicalKey.Keypad6] = LocaleKeys.KeyboardLayout_KeyKeypad6, + [ConfigPhysicalKey.Keypad7] = LocaleKeys.KeyboardLayout_KeyKeypad7, + [ConfigPhysicalKey.Keypad8] = LocaleKeys.KeyboardLayout_KeyKeypad8, + [ConfigPhysicalKey.Keypad9] = LocaleKeys.KeyboardLayout_KeyKeypad9, + [ConfigPhysicalKey.KeypadDivide] = LocaleKeys.KeyboardLayout_KeyKeypadDivide, + [ConfigPhysicalKey.KeypadMultiply] = LocaleKeys.KeyboardLayout_KeyKeypadMultiply, + [ConfigPhysicalKey.KeypadSubtract] = LocaleKeys.KeyboardLayout_KeyKeypadSubtract, + [ConfigPhysicalKey.KeypadAdd] = LocaleKeys.KeyboardLayout_KeyKeypadAdd, + [ConfigPhysicalKey.KeypadDecimal] = LocaleKeys.KeyboardLayout_KeyKeypadDecimal, + [ConfigPhysicalKey.KeypadEnter] = LocaleKeys.KeyboardLayout_KeyKeypadEnter, + [ConfigPhysicalKey.Unbound] = LocaleKeys.KeyboardLayout_KeyUnbound, + }; + + public static string GetString(ConfigPhysicalKey key) + { + if (_localizedKeysMap.TryGetValue(key, out LocaleKeys localeKey)) + { + return GetLocalizedString(localeKey); + } + + if (TryGetPrintableKeySymbol(key, out string label)) + { + return label; + } + + return key.ToString(); + } + + private static bool TryGetPrintableKeySymbol(ConfigPhysicalKey key, out string label) + { + // The legacy enum name for the ISO extra key is misleading, so give it a distinct physical label. + if (key == ConfigPhysicalKey.Grave) + { + label = "<>"; + return true; + } + + if (!AvaloniaKeyboardMappingHelper.TryGetAvaPhysicalKey((InputKey)(int)key, out AvaPhysicalKey avaPhysicalKey)) + { + label = string.Empty; + return false; + } + + label = PhysicalKeyExtensions.ToQwertyKeySymbol(avaPhysicalKey, false); + + if (string.IsNullOrEmpty(label) || label.Length != 1 || char.IsControl(label[0])) + { + label = string.Empty; + return false; + } + + if (char.IsLetter(label[0])) + { + label = char.ToUpperInvariant(label[0]).ToString(); + } + + return true; + } + + private static string GetLocalizedString(LocaleKeys localeKey) + { + if (OperatingSystem.IsMacOS()) + { + localeKey = localeKey switch + { + LocaleKeys.KeyboardLayout_KeyControlLeft => LocaleKeys.KeyboardLayout_KeyMacControlLeft, + LocaleKeys.KeyboardLayout_KeyControlRight => LocaleKeys.KeyboardLayout_KeyMacControlRight, + LocaleKeys.KeyboardLayout_KeyAltLeft => LocaleKeys.KeyboardLayout_KeyMacAltLeft, + LocaleKeys.KeyboardLayout_KeyAltRight => LocaleKeys.KeyboardLayout_KeyMacAltRight, + LocaleKeys.KeyboardLayout_KeyWinLeft => LocaleKeys.KeyboardLayout_KeyMacWinLeft, + LocaleKeys.KeyboardLayout_KeyWinRight => LocaleKeys.KeyboardLayout_KeyMacWinRight, + _ => localeKey + }; + } + + return LocaleManager.Instance[localeKey]; + } + } +} diff --git a/src/Ryujinx/UI/Models/Input/KeyboardInputConfig.cs b/src/Ryujinx/UI/Models/Input/KeyboardInputConfig.cs index de51d9d70..7f3cb121b 100644 --- a/src/Ryujinx/UI/Models/Input/KeyboardInputConfig.cs +++ b/src/Ryujinx/UI/Models/Input/KeyboardInputConfig.cs @@ -13,88 +13,88 @@ namespace Ryujinx.Ava.UI.Models.Input public PlayerIndex PlayerIndex { get; set; } [ObservableProperty] - public partial Key LeftStickUp { get; set; } + public partial PhysicalKey LeftStickUp { get; set; } [ObservableProperty] - public partial Key LeftStickDown { get; set; } + public partial PhysicalKey LeftStickDown { get; set; } [ObservableProperty] - public partial Key LeftStickLeft { get; set; } + public partial PhysicalKey LeftStickLeft { get; set; } [ObservableProperty] - public partial Key LeftStickRight { get; set; } + public partial PhysicalKey LeftStickRight { get; set; } [ObservableProperty] - public partial Key LeftStickButton { get; set; } + public partial PhysicalKey LeftStickButton { get; set; } [ObservableProperty] - public partial Key RightStickUp { get; set; } + public partial PhysicalKey RightStickUp { get; set; } [ObservableProperty] - public partial Key RightStickDown { get; set; } + public partial PhysicalKey RightStickDown { get; set; } [ObservableProperty] - public partial Key RightStickLeft { get; set; } + public partial PhysicalKey RightStickLeft { get; set; } [ObservableProperty] - public partial Key RightStickRight { get; set; } + public partial PhysicalKey RightStickRight { get; set; } [ObservableProperty] - public partial Key RightStickButton { get; set; } + public partial PhysicalKey RightStickButton { get; set; } [ObservableProperty] - public partial Key DpadUp { get; set; } + public partial PhysicalKey DpadUp { get; set; } [ObservableProperty] - public partial Key DpadDown { get; set; } + public partial PhysicalKey DpadDown { get; set; } [ObservableProperty] - public partial Key DpadLeft { get; set; } + public partial PhysicalKey DpadLeft { get; set; } [ObservableProperty] - public partial Key DpadRight { get; set; } + public partial PhysicalKey DpadRight { get; set; } [ObservableProperty] - public partial Key ButtonMinus { get; set; } + public partial PhysicalKey ButtonMinus { get; set; } [ObservableProperty] - public partial Key ButtonPlus { get; set; } + public partial PhysicalKey ButtonPlus { get; set; } [ObservableProperty] - public partial Key ButtonA { get; set; } + public partial PhysicalKey ButtonA { get; set; } [ObservableProperty] - public partial Key ButtonB { get; set; } + public partial PhysicalKey ButtonB { get; set; } [ObservableProperty] - public partial Key ButtonX { get; set; } + public partial PhysicalKey ButtonX { get; set; } [ObservableProperty] - public partial Key ButtonY { get; set; } + public partial PhysicalKey ButtonY { get; set; } [ObservableProperty] - public partial Key ButtonL { get; set; } + public partial PhysicalKey ButtonL { get; set; } [ObservableProperty] - public partial Key ButtonR { get; set; } + public partial PhysicalKey ButtonR { get; set; } [ObservableProperty] - public partial Key ButtonZl { get; set; } + public partial PhysicalKey ButtonZl { get; set; } [ObservableProperty] - public partial Key ButtonZr { get; set; } + public partial PhysicalKey ButtonZr { get; set; } [ObservableProperty] - public partial Key LeftButtonSl { get; set; } + public partial PhysicalKey LeftButtonSl { get; set; } [ObservableProperty] - public partial Key LeftButtonSr { get; set; } + public partial PhysicalKey LeftButtonSr { get; set; } [ObservableProperty] - public partial Key RightButtonSl { get; set; } + public partial PhysicalKey RightButtonSl { get; set; } [ObservableProperty] - public partial Key RightButtonSr { get; set; } + public partial PhysicalKey RightButtonSr { get; set; } public KeyboardInputConfig(InputConfig config) { @@ -153,7 +153,7 @@ namespace Ryujinx.Ava.UI.Models.Input Backend = InputBackendType.WindowKeyboard, PlayerIndex = PlayerIndex, ControllerType = ControllerType, - LeftJoycon = new LeftJoyconCommonConfig + LeftJoycon = new LeftJoyconCommonConfig { DpadUp = DpadUp, DpadDown = DpadDown, @@ -165,7 +165,7 @@ namespace Ryujinx.Ava.UI.Models.Input ButtonSl = LeftButtonSl, ButtonSr = LeftButtonSr, }, - RightJoycon = new RightJoyconCommonConfig + RightJoycon = new RightJoyconCommonConfig { ButtonA = ButtonA, ButtonB = ButtonB, @@ -177,7 +177,7 @@ namespace Ryujinx.Ava.UI.Models.Input ButtonR = ButtonR, ButtonZr = ButtonZr, }, - LeftJoyconStick = new JoyconConfigKeyboardStick + LeftJoyconStick = new JoyconConfigKeyboardStick { StickUp = LeftStickUp, StickDown = LeftStickDown, @@ -185,7 +185,7 @@ namespace Ryujinx.Ava.UI.Models.Input StickLeft = LeftStickLeft, StickButton = LeftStickButton, }, - RightJoyconStick = new JoyconConfigKeyboardStick + RightJoyconStick = new JoyconConfigKeyboardStick { StickUp = RightStickUp, StickDown = RightStickDown, diff --git a/src/Ryujinx/UI/Models/Input/StickVisualizer.cs b/src/Ryujinx/UI/Models/Input/StickVisualizer.cs index f88f4ea72..936268601 100644 --- a/src/Ryujinx/UI/Models/Input/StickVisualizer.cs +++ b/src/Ryujinx/UI/Models/Input/StickVisualizer.cs @@ -154,42 +154,42 @@ namespace Ryujinx.Ava.UI.Models.Input { KeyboardStateSnapshot snapshot = keyboard.GetKeyboardStateSnapshot(); - if (snapshot.IsPressed((Key)KeyboardConfig.LeftStickRight)) + if (snapshot.IsPressed(KeyboardConfig.LeftStickRight.ToInputKey())) { leftBuffer.Item1 += 1; } - if (snapshot.IsPressed((Key)KeyboardConfig.LeftStickLeft)) + if (snapshot.IsPressed(KeyboardConfig.LeftStickLeft.ToInputKey())) { leftBuffer.Item1 -= 1; } - if (snapshot.IsPressed((Key)KeyboardConfig.LeftStickUp)) + if (snapshot.IsPressed(KeyboardConfig.LeftStickUp.ToInputKey())) { leftBuffer.Item2 += 1; } - if (snapshot.IsPressed((Key)KeyboardConfig.LeftStickDown)) + if (snapshot.IsPressed(KeyboardConfig.LeftStickDown.ToInputKey())) { leftBuffer.Item2 -= 1; } - if (snapshot.IsPressed((Key)KeyboardConfig.RightStickRight)) + if (snapshot.IsPressed(KeyboardConfig.RightStickRight.ToInputKey())) { rightBuffer.Item1 += 1; } - if (snapshot.IsPressed((Key)KeyboardConfig.RightStickLeft)) + if (snapshot.IsPressed(KeyboardConfig.RightStickLeft.ToInputKey())) { rightBuffer.Item1 -= 1; } - if (snapshot.IsPressed((Key)KeyboardConfig.RightStickUp)) + if (snapshot.IsPressed(KeyboardConfig.RightStickUp.ToInputKey())) { rightBuffer.Item2 += 1; } - if (snapshot.IsPressed((Key)KeyboardConfig.RightStickDown)) + if (snapshot.IsPressed(KeyboardConfig.RightStickDown.ToInputKey())) { rightBuffer.Item2 -= 1; } diff --git a/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs b/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs index e5f085e0f..5c91bf5ce 100644 --- a/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs @@ -28,7 +28,7 @@ using System.Linq; using System.Text.Json; using ConfigGamepadInputId = Ryujinx.Common.Configuration.Hid.Controller.GamepadInputId; using ConfigStickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId; -using Key = Ryujinx.Common.Configuration.Hid.Key; +using PhysicalKey = Ryujinx.Common.Configuration.Hid.PhysicalKey; namespace Ryujinx.Ava.UI.ViewModels.Input { @@ -290,7 +290,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input { _mainWindow = RyujinxApp.MainWindow; - AvaloniaKeyboardDriver = new AvaloniaKeyboardDriver(owner); + AvaloniaKeyboardDriver = new AvaloniaKeyboardDriver(owner, KeyboardInputMode.Physical); _mainWindow.InputManager.GamepadDriver.OnGamepadConnected += HandleOnGamepadConnected; _mainWindow.InputManager.GamepadDriver.OnGamepadDisconnected += HandleOnGamepadDisconnected; @@ -677,46 +677,46 @@ namespace Ryujinx.Ava.UI.ViewModels.Input Id = id, Name = name, ControllerType = ControllerType.ProController, - LeftJoycon = new LeftJoyconCommonConfig + LeftJoycon = new LeftJoyconCommonConfig { - DpadUp = Key.Up, - DpadDown = Key.Down, - DpadLeft = Key.Left, - DpadRight = Key.Right, - ButtonMinus = Key.Minus, - ButtonL = Key.E, - ButtonZl = Key.Q, - ButtonSl = Key.Unbound, - ButtonSr = Key.Unbound, + DpadUp = PhysicalKey.Up, + DpadDown = PhysicalKey.Down, + DpadLeft = PhysicalKey.Left, + DpadRight = PhysicalKey.Right, + ButtonMinus = PhysicalKey.Minus, + ButtonL = PhysicalKey.E, + ButtonZl = PhysicalKey.Q, + ButtonSl = PhysicalKey.Unbound, + ButtonSr = PhysicalKey.Unbound, }, LeftJoyconStick = - new JoyconConfigKeyboardStick + new JoyconConfigKeyboardStick { - StickUp = Key.W, - StickDown = Key.S, - StickLeft = Key.A, - StickRight = Key.D, - StickButton = Key.F, + StickUp = PhysicalKey.W, + StickDown = PhysicalKey.S, + StickLeft = PhysicalKey.A, + StickRight = PhysicalKey.D, + StickButton = PhysicalKey.F, }, - RightJoycon = new RightJoyconCommonConfig + RightJoycon = new RightJoyconCommonConfig { - ButtonA = Key.Z, - ButtonB = Key.X, - ButtonX = Key.C, - ButtonY = Key.V, - ButtonPlus = Key.Plus, - ButtonR = Key.U, - ButtonZr = Key.O, - ButtonSl = Key.Unbound, - ButtonSr = Key.Unbound, + ButtonA = PhysicalKey.Z, + ButtonB = PhysicalKey.X, + ButtonX = PhysicalKey.C, + ButtonY = PhysicalKey.V, + ButtonPlus = PhysicalKey.Plus, + ButtonR = PhysicalKey.U, + ButtonZr = PhysicalKey.O, + ButtonSl = PhysicalKey.Unbound, + ButtonSr = PhysicalKey.Unbound, }, - RightJoyconStick = new JoyconConfigKeyboardStick + RightJoyconStick = new JoyconConfigKeyboardStick { - StickUp = Key.I, - StickDown = Key.K, - StickLeft = Key.J, - StickRight = Key.L, - StickButton = Key.H, + StickUp = PhysicalKey.I, + StickDown = PhysicalKey.K, + StickLeft = PhysicalKey.J, + StickRight = PhysicalKey.L, + StickButton = PhysicalKey.H, }, }; } diff --git a/src/Ryujinx/UI/Views/Input/KeyboardInputView.axaml.cs b/src/Ryujinx/UI/Views/Input/KeyboardInputView.axaml.cs index 668e1220c..e7b0daf80 100644 --- a/src/Ryujinx/UI/Views/Input/KeyboardInputView.axaml.cs +++ b/src/Ryujinx/UI/Views/Input/KeyboardInputView.axaml.cs @@ -12,7 +12,7 @@ using Ryujinx.Input.Assigner; using System; using System.Collections.Generic; using Button = Ryujinx.Input.Button; -using Key = Ryujinx.Common.Configuration.Hid.Key; +using PhysicalKey = Ryujinx.Common.Configuration.Hid.PhysicalKey; namespace Ryujinx.Ava.UI.Views.Input { @@ -78,88 +78,88 @@ namespace Ryujinx.Ava.UI.Views.Input switch (button.Name) { case "ButtonZl": - ViewModel.Config.ButtonZl = buttonValue.AsHidType(); + ViewModel.Config.ButtonZl = buttonValue.AsHidType(); break; case "ButtonL": - ViewModel.Config.ButtonL = buttonValue.AsHidType(); + ViewModel.Config.ButtonL = buttonValue.AsHidType(); break; case "ButtonMinus": - ViewModel.Config.ButtonMinus = buttonValue.AsHidType(); + ViewModel.Config.ButtonMinus = buttonValue.AsHidType(); break; case "LeftStickButton": - ViewModel.Config.LeftStickButton = buttonValue.AsHidType(); + ViewModel.Config.LeftStickButton = buttonValue.AsHidType(); break; case "LeftStickUp": - ViewModel.Config.LeftStickUp = buttonValue.AsHidType(); + ViewModel.Config.LeftStickUp = buttonValue.AsHidType(); break; case "LeftStickDown": - ViewModel.Config.LeftStickDown = buttonValue.AsHidType(); + ViewModel.Config.LeftStickDown = buttonValue.AsHidType(); break; case "LeftStickRight": - ViewModel.Config.LeftStickRight = buttonValue.AsHidType(); + ViewModel.Config.LeftStickRight = buttonValue.AsHidType(); break; case "LeftStickLeft": - ViewModel.Config.LeftStickLeft = buttonValue.AsHidType(); + ViewModel.Config.LeftStickLeft = buttonValue.AsHidType(); break; case "DpadUp": - ViewModel.Config.DpadUp = buttonValue.AsHidType(); + ViewModel.Config.DpadUp = buttonValue.AsHidType(); break; case "DpadDown": - ViewModel.Config.DpadDown = buttonValue.AsHidType(); + ViewModel.Config.DpadDown = buttonValue.AsHidType(); break; case "DpadLeft": - ViewModel.Config.DpadLeft = buttonValue.AsHidType(); + ViewModel.Config.DpadLeft = buttonValue.AsHidType(); break; case "DpadRight": - ViewModel.Config.DpadRight = buttonValue.AsHidType(); + ViewModel.Config.DpadRight = buttonValue.AsHidType(); break; case "LeftButtonSr": - ViewModel.Config.LeftButtonSr = buttonValue.AsHidType(); + ViewModel.Config.LeftButtonSr = buttonValue.AsHidType(); break; case "LeftButtonSl": - ViewModel.Config.LeftButtonSl = buttonValue.AsHidType(); + ViewModel.Config.LeftButtonSl = buttonValue.AsHidType(); break; case "RightButtonSr": - ViewModel.Config.RightButtonSr = buttonValue.AsHidType(); + ViewModel.Config.RightButtonSr = buttonValue.AsHidType(); break; case "RightButtonSl": - ViewModel.Config.RightButtonSl = buttonValue.AsHidType(); + ViewModel.Config.RightButtonSl = buttonValue.AsHidType(); break; case "ButtonZr": - ViewModel.Config.ButtonZr = buttonValue.AsHidType(); + ViewModel.Config.ButtonZr = buttonValue.AsHidType(); break; case "ButtonR": - ViewModel.Config.ButtonR = buttonValue.AsHidType(); + ViewModel.Config.ButtonR = buttonValue.AsHidType(); break; case "ButtonPlus": - ViewModel.Config.ButtonPlus = buttonValue.AsHidType(); + ViewModel.Config.ButtonPlus = buttonValue.AsHidType(); break; case "ButtonA": - ViewModel.Config.ButtonA = buttonValue.AsHidType(); + ViewModel.Config.ButtonA = buttonValue.AsHidType(); break; case "ButtonB": - ViewModel.Config.ButtonB = buttonValue.AsHidType(); + ViewModel.Config.ButtonB = buttonValue.AsHidType(); break; case "ButtonX": - ViewModel.Config.ButtonX = buttonValue.AsHidType(); + ViewModel.Config.ButtonX = buttonValue.AsHidType(); break; case "ButtonY": - ViewModel.Config.ButtonY = buttonValue.AsHidType(); + ViewModel.Config.ButtonY = buttonValue.AsHidType(); break; case "RightStickButton": - ViewModel.Config.RightStickButton = buttonValue.AsHidType(); + ViewModel.Config.RightStickButton = buttonValue.AsHidType(); break; case "RightStickUp": - ViewModel.Config.RightStickUp = buttonValue.AsHidType(); + ViewModel.Config.RightStickUp = buttonValue.AsHidType(); break; case "RightStickDown": - ViewModel.Config.RightStickDown = buttonValue.AsHidType(); + ViewModel.Config.RightStickDown = buttonValue.AsHidType(); break; case "RightStickRight": - ViewModel.Config.RightStickRight = buttonValue.AsHidType(); + ViewModel.Config.RightStickRight = buttonValue.AsHidType(); break; case "RightStickLeft": - ViewModel.Config.RightStickLeft = buttonValue.AsHidType(); + ViewModel.Config.RightStickLeft = buttonValue.AsHidType(); break; } } @@ -207,34 +207,34 @@ namespace Ryujinx.Ava.UI.Views.Input { Dictionary buttonActions = new() { - { "ButtonZl", () => ViewModel.Config.ButtonZl = Key.Unbound }, - { "ButtonL", () => ViewModel.Config.ButtonL = Key.Unbound }, - { "ButtonMinus", () => ViewModel.Config.ButtonMinus = Key.Unbound }, - { "LeftStickButton", () => ViewModel.Config.LeftStickButton = Key.Unbound }, - { "LeftStickUp", () => ViewModel.Config.LeftStickUp = Key.Unbound }, - { "LeftStickDown", () => ViewModel.Config.LeftStickDown = Key.Unbound }, - { "LeftStickRight", () => ViewModel.Config.LeftStickRight = Key.Unbound }, - { "LeftStickLeft", () => ViewModel.Config.LeftStickLeft = Key.Unbound }, - { "DpadUp", () => ViewModel.Config.DpadUp = Key.Unbound }, - { "DpadDown", () => ViewModel.Config.DpadDown = Key.Unbound }, - { "DpadLeft", () => ViewModel.Config.DpadLeft = Key.Unbound }, - { "DpadRight", () => ViewModel.Config.DpadRight = Key.Unbound }, - { "LeftButtonSr", () => ViewModel.Config.LeftButtonSr = Key.Unbound }, - { "LeftButtonSl", () => ViewModel.Config.LeftButtonSl = Key.Unbound }, - { "RightButtonSr", () => ViewModel.Config.RightButtonSr = Key.Unbound }, - { "RightButtonSl", () => ViewModel.Config.RightButtonSl = Key.Unbound }, - { "ButtonZr", () => ViewModel.Config.ButtonZr = Key.Unbound }, - { "ButtonR", () => ViewModel.Config.ButtonR = Key.Unbound }, - { "ButtonPlus", () => ViewModel.Config.ButtonPlus = Key.Unbound }, - { "ButtonA", () => ViewModel.Config.ButtonA = Key.Unbound }, - { "ButtonB", () => ViewModel.Config.ButtonB = Key.Unbound }, - { "ButtonX", () => ViewModel.Config.ButtonX = Key.Unbound }, - { "ButtonY", () => ViewModel.Config.ButtonY = Key.Unbound }, - { "RightStickButton", () => ViewModel.Config.RightStickButton = Key.Unbound }, - { "RightStickUp", () => ViewModel.Config.RightStickUp = Key.Unbound }, - { "RightStickDown", () => ViewModel.Config.RightStickDown = Key.Unbound }, - { "RightStickRight", () => ViewModel.Config.RightStickRight = Key.Unbound }, - { "RightStickLeft", () => ViewModel.Config.RightStickLeft = Key.Unbound } + { "ButtonZl", () => ViewModel.Config.ButtonZl = PhysicalKey.Unbound }, + { "ButtonL", () => ViewModel.Config.ButtonL = PhysicalKey.Unbound }, + { "ButtonMinus", () => ViewModel.Config.ButtonMinus = PhysicalKey.Unbound }, + { "LeftStickButton", () => ViewModel.Config.LeftStickButton = PhysicalKey.Unbound }, + { "LeftStickUp", () => ViewModel.Config.LeftStickUp = PhysicalKey.Unbound }, + { "LeftStickDown", () => ViewModel.Config.LeftStickDown = PhysicalKey.Unbound }, + { "LeftStickRight", () => ViewModel.Config.LeftStickRight = PhysicalKey.Unbound }, + { "LeftStickLeft", () => ViewModel.Config.LeftStickLeft = PhysicalKey.Unbound }, + { "DpadUp", () => ViewModel.Config.DpadUp = PhysicalKey.Unbound }, + { "DpadDown", () => ViewModel.Config.DpadDown = PhysicalKey.Unbound }, + { "DpadLeft", () => ViewModel.Config.DpadLeft = PhysicalKey.Unbound }, + { "DpadRight", () => ViewModel.Config.DpadRight = PhysicalKey.Unbound }, + { "LeftButtonSr", () => ViewModel.Config.LeftButtonSr = PhysicalKey.Unbound }, + { "LeftButtonSl", () => ViewModel.Config.LeftButtonSl = PhysicalKey.Unbound }, + { "RightButtonSr", () => ViewModel.Config.RightButtonSr = PhysicalKey.Unbound }, + { "RightButtonSl", () => ViewModel.Config.RightButtonSl = PhysicalKey.Unbound }, + { "ButtonZr", () => ViewModel.Config.ButtonZr = PhysicalKey.Unbound }, + { "ButtonR", () => ViewModel.Config.ButtonR = PhysicalKey.Unbound }, + { "ButtonPlus", () => ViewModel.Config.ButtonPlus = PhysicalKey.Unbound }, + { "ButtonA", () => ViewModel.Config.ButtonA = PhysicalKey.Unbound }, + { "ButtonB", () => ViewModel.Config.ButtonB = PhysicalKey.Unbound }, + { "ButtonX", () => ViewModel.Config.ButtonX = PhysicalKey.Unbound }, + { "ButtonY", () => ViewModel.Config.ButtonY = PhysicalKey.Unbound }, + { "RightStickButton", () => ViewModel.Config.RightStickButton = PhysicalKey.Unbound }, + { "RightStickUp", () => ViewModel.Config.RightStickUp = PhysicalKey.Unbound }, + { "RightStickDown", () => ViewModel.Config.RightStickDown = PhysicalKey.Unbound }, + { "RightStickRight", () => ViewModel.Config.RightStickRight = PhysicalKey.Unbound }, + { "RightStickLeft", () => ViewModel.Config.RightStickLeft = PhysicalKey.Unbound } }; if (buttonActions.TryGetValue(_currentAssigner.ToggledButton.Name, out Action action)) diff --git a/src/Ryujinx/UI/Views/Settings/SettingsHotkeysView.axaml.cs b/src/Ryujinx/UI/Views/Settings/SettingsHotkeysView.axaml.cs index b9a5462b2..a0a924c5a 100644 --- a/src/Ryujinx/UI/Views/Settings/SettingsHotkeysView.axaml.cs +++ b/src/Ryujinx/UI/Views/Settings/SettingsHotkeysView.axaml.cs @@ -34,7 +34,7 @@ namespace Ryujinx.Ava.UI.Views.Settings } } - _avaloniaKeyboardDriver = new AvaloniaKeyboardDriver(this); + _avaloniaKeyboardDriver = new AvaloniaKeyboardDriver(this, KeyboardInputMode.Semantic); } protected override void OnPointerReleased(PointerReleasedEventArgs e) diff --git a/src/Ryujinx/UI/Windows/MainWindow.axaml.cs b/src/Ryujinx/UI/Windows/MainWindow.axaml.cs index e7934f38a..1d8bcdfe9 100644 --- a/src/Ryujinx/UI/Windows/MainWindow.axaml.cs +++ b/src/Ryujinx/UI/Windows/MainWindow.axaml.cs @@ -30,6 +30,7 @@ using Ryujinx.HLE.HOS; using Ryujinx.HLE.HOS.Services.Account.Acc; using Ryujinx.Input.HLE; using Ryujinx.Input.SDL3; +using Ryujinx.Input; using System; using System.Collections.Generic; using System.Linq; @@ -105,7 +106,7 @@ namespace Ryujinx.Ava.UI.Windows if (Program.PreviewerDetached) { - InputManager = new InputManager(new AvaloniaKeyboardDriver(this), new SDL3GamepadDriver()); + InputManager = new InputManager(new AvaloniaKeyboardDriver(this, KeyboardInputMode.Semantic), new SDL3GamepadDriver()); _ = this.GetObservable(IsActiveProperty).Subscribe(it => ViewModel.IsActive = it); this.ScalingChanged += OnScalingChanged;