mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[KBM]Fix concurrent shortcut remap locking key (#18499)
This commit is contained in:
@@ -586,22 +586,36 @@ namespace KeyboardEventHandlers
|
|||||||
if (newRemapping.RemapToKey())
|
if (newRemapping.RemapToKey())
|
||||||
{
|
{
|
||||||
DWORD to = std::get<0>(newRemapping.targetShortcut);
|
DWORD to = std::get<0>(newRemapping.targetShortcut);
|
||||||
key_count = from.Size() - 1 + 1;
|
bool isLastKeyStillPressed = ii.GetVirtualKeyState((WORD)from.actionKey);
|
||||||
|
key_count = from.Size() - 1 + 1 + (isLastKeyStillPressed ? 1 : 0);
|
||||||
keyEventList = new INPUT[key_count]();
|
keyEventList = new INPUT[key_count]();
|
||||||
memset(keyEventList, 0, sizeof(keyEventList));
|
memset(keyEventList, 0, sizeof(keyEventList));
|
||||||
int i = 0;
|
int i = 0;
|
||||||
Helpers::SetModifierKeyEvents(from, it->second.winKeyInvoked, keyEventList, i, false, KeyboardManagerConstants::KEYBOARDMANAGER_SHORTCUT_FLAG);
|
Helpers::SetModifierKeyEvents(from, it->second.winKeyInvoked, keyEventList, i, false, KeyboardManagerConstants::KEYBOARDMANAGER_SHORTCUT_FLAG);
|
||||||
|
if (ii.GetVirtualKeyState((WORD)from.actionKey))
|
||||||
|
{
|
||||||
|
// If the action key from the last shortcut is still being pressed, release it.
|
||||||
|
Helpers::SetKeyEvent(keyEventList, i, INPUT_KEYBOARD, (WORD)from.actionKey, KEYEVENTF_KEYUP, KeyboardManagerConstants::KEYBOARDMANAGER_SHORTCUT_FLAG);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
Helpers::SetKeyEvent(keyEventList, i, INPUT_KEYBOARD, (WORD)to, 0, KeyboardManagerConstants::KEYBOARDMANAGER_SHORTCUT_FLAG);
|
Helpers::SetKeyEvent(keyEventList, i, INPUT_KEYBOARD, (WORD)to, 0, KeyboardManagerConstants::KEYBOARDMANAGER_SHORTCUT_FLAG);
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
Shortcut to = std::get<Shortcut>(newRemapping.targetShortcut);
|
Shortcut to = std::get<Shortcut>(newRemapping.targetShortcut);
|
||||||
key_count = from.Size() - 1 + to.Size() - 1 - 2* from.GetCommonModifiersCount(to) + 1;
|
bool isLastKeyStillPressed = ii.GetVirtualKeyState((WORD)from.actionKey);
|
||||||
|
|
||||||
|
key_count = from.Size() - 1 + to.Size() - 1 - 2* from.GetCommonModifiersCount(to) + 1 + (isLastKeyStillPressed ? 1 : 0);
|
||||||
keyEventList = new INPUT[key_count]();
|
keyEventList = new INPUT[key_count]();
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
Helpers::SetModifierKeyEvents(from, it->second.winKeyInvoked, keyEventList, i, false, KeyboardManagerConstants::KEYBOARDMANAGER_SHORTCUT_FLAG, to);
|
Helpers::SetModifierKeyEvents(from, it->second.winKeyInvoked, keyEventList, i, false, KeyboardManagerConstants::KEYBOARDMANAGER_SHORTCUT_FLAG, to);
|
||||||
|
if (ii.GetVirtualKeyState((WORD)from.actionKey))
|
||||||
|
{
|
||||||
|
// If the action key from the last shortcut is still being pressed, release it.
|
||||||
|
Helpers::SetKeyEvent(keyEventList, i, INPUT_KEYBOARD, (WORD)from.actionKey, KEYEVENTF_KEYUP, KeyboardManagerConstants::KEYBOARDMANAGER_SHORTCUT_FLAG);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
Helpers::SetModifierKeyEvents(to, it->second.winKeyInvoked, keyEventList, i, true, KeyboardManagerConstants::KEYBOARDMANAGER_SHORTCUT_FLAG, from);
|
Helpers::SetModifierKeyEvents(to, it->second.winKeyInvoked, keyEventList, i, true, KeyboardManagerConstants::KEYBOARDMANAGER_SHORTCUT_FLAG, from);
|
||||||
|
|
||||||
Helpers::SetKeyEvent(keyEventList, i, INPUT_KEYBOARD, (WORD)to.actionKey, 0, KeyboardManagerConstants::KEYBOARDMANAGER_SHORTCUT_FLAG);
|
Helpers::SetKeyEvent(keyEventList, i, INPUT_KEYBOARD, (WORD)to.actionKey, 0, KeyboardManagerConstants::KEYBOARDMANAGER_SHORTCUT_FLAG);
|
||||||
newRemapping.isShortcutInvoked = true;
|
newRemapping.isShortcutInvoked = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user