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.
This commit is contained in:
Sour 2020-02-23 10:01:05 -05:00
parent 74e8f39ea1
commit e197e5ee2b
3 changed files with 16 additions and 10 deletions

View file

@ -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<ControllerInfo>();
PreferenceInfo.DefaultsInitialized = false;
PreferenceInfo.NeedWindowsShortcutReset = false;
}
InputInfo.InitializeDefaults();
PreferenceInfo.InitializeDefaults();
}

View file

@ -59,6 +59,7 @@ namespace Mesen.GUI.Config
public DateTime CloudLastSync = DateTime.MinValue;
public bool DefaultsInitialized = false;
public bool NeedWindowsShortcutReset = true;
public List<ShortcutKeyInfo> ShortcutKeys1;
public List<ShortcutKeyInfo> ShortcutKeys2;

View file

@ -230,12 +230,11 @@ WindowsKeyManager::WindowsKeyManager(shared_ptr<Console> 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<uint32_t> 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;
}
}