Fix Ctrl/Alt/Shift single key remapping (#2217)

* Added preprocessing step for edit keyboard buffer

* Fixed Ctrl\Alt\Shift single key remapping
This commit is contained in:
Arjun Balgovind 2020-04-21 13:40:31 -07:00 committed by GitHub
parent 7856495d59
commit 2f244bca85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -153,11 +153,45 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan
// Load existing remaps into UI
std::unique_lock<std::mutex> lock(keyboardManagerState.singleKeyReMap_mutex);
for (const auto& it : keyboardManagerState.singleKeyReMap)
std::unordered_map<DWORD, DWORD> singleKeyRemapCopy = keyboardManagerState.singleKeyReMap;
lock.unlock();
// Pre process the table to combine L and R versions of Ctrl/Alt/Shift that are mapped to the same key
if (singleKeyRemapCopy.find(VK_LCONTROL) != singleKeyRemapCopy.end() && singleKeyRemapCopy.find(VK_RCONTROL) != singleKeyRemapCopy.end())
{
// If they are mapped to the same key, delete those entries and set the common version
if (singleKeyRemapCopy[VK_LCONTROL] == singleKeyRemapCopy[VK_RCONTROL])
{
singleKeyRemapCopy[VK_CONTROL] = singleKeyRemapCopy[VK_LCONTROL];
singleKeyRemapCopy.erase(VK_LCONTROL);
singleKeyRemapCopy.erase(VK_RCONTROL);
}
}
if (singleKeyRemapCopy.find(VK_LMENU) != singleKeyRemapCopy.end() && singleKeyRemapCopy.find(VK_RMENU) != singleKeyRemapCopy.end())
{
// If they are mapped to the same key, delete those entries and set the common version
if (singleKeyRemapCopy[VK_LMENU] == singleKeyRemapCopy[VK_RMENU])
{
singleKeyRemapCopy[VK_MENU] = singleKeyRemapCopy[VK_LMENU];
singleKeyRemapCopy.erase(VK_LMENU);
singleKeyRemapCopy.erase(VK_RMENU);
}
}
if (singleKeyRemapCopy.find(VK_LSHIFT) != singleKeyRemapCopy.end() && singleKeyRemapCopy.find(VK_RSHIFT) != singleKeyRemapCopy.end())
{
// If they are mapped to the same key, delete those entries and set the common version
if (singleKeyRemapCopy[VK_LSHIFT] == singleKeyRemapCopy[VK_RSHIFT])
{
singleKeyRemapCopy[VK_SHIFT] = singleKeyRemapCopy[VK_LSHIFT];
singleKeyRemapCopy.erase(VK_LSHIFT);
singleKeyRemapCopy.erase(VK_RSHIFT);
}
}
for (const auto& it : singleKeyRemapCopy)
{
SingleKeyRemapControl::AddNewControlKeyRemapRow(keyRemapTable, keyboardRemapControlObjects, it.first, it.second);
}
lock.unlock();
// Main Header Apply button
Button applyButton;
@ -177,7 +211,30 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan
if (originalKey != NULL && newKey != NULL)
{
bool result = keyboardManagerState.AddSingleKeyRemap(originalKey, newKey);
// If Ctrl/Alt/Shift are added, add their L and R versions instead to the same key
bool result = false;
bool res1, res2;
switch (originalKey)
{
case VK_CONTROL:
res1 = keyboardManagerState.AddSingleKeyRemap(VK_LCONTROL, newKey);
res2 = keyboardManagerState.AddSingleKeyRemap(VK_RCONTROL, newKey);
result = res1 && res2;
break;
case VK_MENU:
res1 = keyboardManagerState.AddSingleKeyRemap(VK_LMENU, newKey);
res2 = keyboardManagerState.AddSingleKeyRemap(VK_RMENU, newKey);
result = res1 && res2;
break;
case VK_SHIFT:
res1 = keyboardManagerState.AddSingleKeyRemap(VK_LSHIFT, newKey);
res2 = keyboardManagerState.AddSingleKeyRemap(VK_RSHIFT, newKey);
result = res1 && res2;
break;
default:
result = keyboardManagerState.AddSingleKeyRemap(originalKey, newKey);
}
if (!result)
{
isSuccess = false;