From 801f32a719e7d28071e205a0bed5e7dbceb41b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Trzci=C5=84ski?= Date: Mon, 12 Dec 2022 11:44:29 +0100 Subject: [PATCH] Improve `VirtualKeyCode` to `ToWindowsInput` mapping --- SteamController/Devices/KeyboardController.cs | 12 ------------ .../Profiles/DefaultBackPanelShortcutsProfile.cs | 10 ++++++---- SteamController/ProfilesSettings/VirtualKeyCode.cs | 13 +++++++++++++ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/SteamController/Devices/KeyboardController.cs b/SteamController/Devices/KeyboardController.cs index 3a0da3e..46d8759 100644 --- a/SteamController/Devices/KeyboardController.cs +++ b/SteamController/Devices/KeyboardController.cs @@ -20,18 +20,6 @@ namespace SteamController.Devices { } - public bool this[ProfilesSettings.VirtualKeyCode key] - { - get { return this[(VirtualKeyCode)key]; } - set { this[(VirtualKeyCode)key] = value; } - } - - public bool this[System.Windows.Input.Key key] - { - get { return this[(VirtualKeyCode)System.Windows.Input.KeyInterop.VirtualKeyFromKey(key)]; } - set { this[(VirtualKeyCode)System.Windows.Input.KeyInterop.VirtualKeyFromKey(key)] = value; } - } - public bool this[System.Windows.Forms.Keys key] { get diff --git a/SteamController/Profiles/DefaultBackPanelShortcutsProfile.cs b/SteamController/Profiles/DefaultBackPanelShortcutsProfile.cs index 8793bd9..5c9b7cd 100644 --- a/SteamController/Profiles/DefaultBackPanelShortcutsProfile.cs +++ b/SteamController/Profiles/DefaultBackPanelShortcutsProfile.cs @@ -1,3 +1,5 @@ +using SteamController.ProfilesSettings; + namespace SteamController.Profiles { public abstract class DefaultBackPanelShortcutsProfile : DefaultGuideShortcutsProfile @@ -20,10 +22,10 @@ namespace SteamController.Profiles { var settings = BackPanelSettings; - c.Keyboard[settings.L4_KEY] = c.Steam.BtnL4; - c.Keyboard[settings.L5_KEY] = c.Steam.BtnL5; - c.Keyboard[settings.R4_KEY] = c.Steam.BtnR4; - c.Keyboard[settings.R5_KEY] = c.Steam.BtnR5; + c.Keyboard[settings.L4_KEY.ToWindowsInput()] = c.Steam.BtnL4; + c.Keyboard[settings.L5_KEY.ToWindowsInput()] = c.Steam.BtnL5; + c.Keyboard[settings.R4_KEY.ToWindowsInput()] = c.Steam.BtnR4; + c.Keyboard[settings.R5_KEY.ToWindowsInput()] = c.Steam.BtnR5; } } } diff --git a/SteamController/ProfilesSettings/VirtualKeyCode.cs b/SteamController/ProfilesSettings/VirtualKeyCode.cs index 3c12abc..567ac7c 100644 --- a/SteamController/ProfilesSettings/VirtualKeyCode.cs +++ b/SteamController/ProfilesSettings/VirtualKeyCode.cs @@ -389,4 +389,17 @@ namespace SteamController.ProfilesSettings // Windows 2000/XP: Start Application 2 key LAUNCH_APP2 = 183 } + + public static class VirtualKeyCodeExtensions + { + public static WindowsInput.VirtualKeyCode ToWindowsInput(this VirtualKeyCode code) + { + return (WindowsInput.VirtualKeyCode)code; + } + + public static WindowsInput.VirtualKeyCode ToWindowsInput(this System.Windows.Input.Key key) + { + return (WindowsInput.VirtualKeyCode)System.Windows.Input.KeyInterop.VirtualKeyFromKey(key); + } + } }