mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 19:57:57 +01:00
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:
@@ -153,11 +153,45 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan
|
|||||||
|
|
||||||
// Load existing remaps into UI
|
// Load existing remaps into UI
|
||||||
std::unique_lock<std::mutex> lock(keyboardManagerState.singleKeyReMap_mutex);
|
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);
|
SingleKeyRemapControl::AddNewControlKeyRemapRow(keyRemapTable, keyboardRemapControlObjects, it.first, it.second);
|
||||||
}
|
}
|
||||||
lock.unlock();
|
|
||||||
|
|
||||||
// Main Header Apply button
|
// Main Header Apply button
|
||||||
Button applyButton;
|
Button applyButton;
|
||||||
@@ -177,7 +211,30 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan
|
|||||||
|
|
||||||
if (originalKey != NULL && newKey != NULL)
|
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)
|
if (!result)
|
||||||
{
|
{
|
||||||
isSuccess = false;
|
isSuccess = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user