From e197e5ee2b2c05876af7ea7c79e58d2f247f74a3 Mon Sep 17 00:00:00 2001 From: Sour Date: Sun, 23 Feb 2020 10:01:05 -0500 Subject: [PATCH] Input: Fixed default shortcuts & shortcut display when using non-qwerty layouts This resets all non-debugger shortcut keys to their default values due to values saved in the config switching from scan codes to virtual key codes. --- GUI.NET/Config/Configuration.cs | 7 +++++++ GUI.NET/Config/PreferenceInfo.cs | 1 + Windows/WindowsKeyManager.cpp | 18 ++++++++---------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/GUI.NET/Config/Configuration.cs b/GUI.NET/Config/Configuration.cs index 34b97fc8..74688e39 100644 --- a/GUI.NET/Config/Configuration.cs +++ b/GUI.NET/Config/Configuration.cs @@ -92,6 +92,13 @@ namespace Mesen.GUI.Config public void InitializeDefaults() { + if(!Program.IsMono && PreferenceInfo.NeedWindowsShortcutReset) { + //TODO: Temporary code to reset shortcuts in 0.9.9 dev builds, will need to be moved to upgrade process for next release + InputInfo.Controllers = new List(); + PreferenceInfo.DefaultsInitialized = false; + PreferenceInfo.NeedWindowsShortcutReset = false; + } + InputInfo.InitializeDefaults(); PreferenceInfo.InitializeDefaults(); } diff --git a/GUI.NET/Config/PreferenceInfo.cs b/GUI.NET/Config/PreferenceInfo.cs index 213ae054..9c866692 100644 --- a/GUI.NET/Config/PreferenceInfo.cs +++ b/GUI.NET/Config/PreferenceInfo.cs @@ -59,6 +59,7 @@ namespace Mesen.GUI.Config public DateTime CloudLastSync = DateTime.MinValue; public bool DefaultsInitialized = false; + public bool NeedWindowsShortcutReset = true; public List ShortcutKeys1; public List ShortcutKeys2; diff --git a/Windows/WindowsKeyManager.cpp b/Windows/WindowsKeyManager.cpp index 5834fd6d..6e34fe93 100644 --- a/Windows/WindowsKeyManager.cpp +++ b/Windows/WindowsKeyManager.cpp @@ -230,12 +230,11 @@ WindowsKeyManager::WindowsKeyManager(shared_ptr console, HWND hWnd) for(KeyDefinition &keyDef : _keyDefinitions) { _keyNames[keyDef.keyCode] = keyDef.description; - _keyExtendedNames[keyDef.keyCode] = keyDef.extDescription.empty() ? "Ext " + keyDef.description : keyDef.extDescription; + _keyExtendedNames[keyDef.keyCode | 0x100] = keyDef.extDescription.empty() ? "Ext " + keyDef.description : keyDef.extDescription; - uint32_t keyCode = keyDef.keyCode <= 0xFFFF ? MapVirtualKeyEx(keyDef.keyCode & 0xFF, MAPVK_VK_TO_VSC, nullptr) : keyDef.keyCode; - _keyCodes[keyDef.description] = keyCode; + _keyCodes[keyDef.description] = keyDef.keyCode; if(!keyDef.extDescription.empty()) { - _keyCodes[keyDef.extDescription] = 0x100 | keyCode; + _keyCodes[keyDef.extDescription] = 0x100 | (keyDef.keyCode); } } @@ -348,10 +347,9 @@ vector WindowsKeyManager::GetPressedKeys() return result; } -string WindowsKeyManager::GetKeyName(uint32_t scanCode) +string WindowsKeyManager::GetKeyName(uint32_t keyCode) { - uint32_t keyCode = scanCode <= 0xFFFF ? MapVirtualKeyEx(scanCode & 0xFF, MAPVK_VSC_TO_VK, nullptr) : scanCode; - bool extendedKey = (scanCode <= 0xFFFF && scanCode & 0x100); + bool extendedKey = (keyCode <= 0xFFFF && (keyCode & 0x100)); auto keyDef = (extendedKey ? _keyExtendedNames : _keyNames).find(keyCode); if(keyDef != (extendedKey ? _keyExtendedNames : _keyNames).end()) { return keyDef->second; @@ -383,12 +381,12 @@ void WindowsKeyManager::SetKeyState(uint16_t scanCode, bool state) if(scanCode > 0x1FF) { _mouseState[scanCode & 0x03] = state; } else { - uint32_t keyCode = MapVirtualKeyEx(scanCode & 0xFF, MAPVK_VSC_TO_VK, nullptr); + uint32_t keyCode = MapVirtualKeyEx(scanCode & 0xFF, MAPVK_VSC_TO_VK, GetKeyboardLayout(0)); if(keyCode >= 0x10 && keyCode <= 0x12) { //Ignore "ext" flag for alt, ctrl & shift - scanCode = MapVirtualKeyEx(keyCode, MAPVK_VK_TO_VSC, nullptr); + scanCode = MapVirtualKeyEx(keyCode, MAPVK_VK_TO_VSC, GetKeyboardLayout(0)); } - _keyState[scanCode & 0x1FF] = state; + _keyState[keyCode | (scanCode & 0x100)] = state; } }