mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-24 04:00:02 +01:00
[KeyboardManager]Fix mapping shift to numpad (#35890)
* Keyboard Manger fix numpad as shift Fixed shift not being released if a numpad key as shift. * Added comments * Fix typo * Fix the numpad unlocked key not working if the locked version is overridden by shift * Fix spelling check. * Revert the VK_CLEAR change. --------- Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
This commit is contained in:
@@ -32,6 +32,58 @@ namespace
|
||||
{
|
||||
return data->lParam->dwExtraInfo & CommonSharedConstants::KEYBOARDMANAGER_INJECTED_FLAG;
|
||||
}
|
||||
|
||||
void UpdateNumpadWithShift(LowlevelKeyboardEvent* data, State& state)
|
||||
{
|
||||
//Function for fixing numpad when used as shift https://github.com/microsoft/PowerToys/issues/22346
|
||||
//VK_CLEAR is not encoded in IsNumpadOriginated
|
||||
if (Helpers::IsNumpadOriginated(data->lParam->vkCode) || data->lParam->vkCode == VK_CLEAR)
|
||||
{
|
||||
// Decode it. If it is VK_CLEAR it will do nothing
|
||||
DWORD decodedKey = Helpers::ClearKeyNumpadOrigin(data->lParam->vkCode);
|
||||
//check if we already have a stored scanID
|
||||
auto scanKey = MapVirtualKey(decodedKey, MAPVK_VK_TO_VSC);
|
||||
auto it = state.scanMap.find(scanKey);
|
||||
if (it != state.scanMap.end())
|
||||
{
|
||||
auto keyIt = state.GetSingleKeyRemap(it->second);
|
||||
if (keyIt)
|
||||
{
|
||||
//if key is stored as shift replace it with the numpad key
|
||||
auto keyValue = keyIt.value();
|
||||
if (keyValue->second.index() == 0)
|
||||
{
|
||||
auto key = std::get<DWORD>(keyValue->second);
|
||||
if (key == VK_LSHIFT || key == VK_RSHIFT || key == VK_SHIFT)
|
||||
{
|
||||
if (state.numpadKeyPressed[it->second])
|
||||
{
|
||||
//replace it with original numpad
|
||||
data->lParam->vkCode = it->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (keyValue->second.index() == 1)
|
||||
{
|
||||
auto key = std::get<Shortcut>(keyValue->second);
|
||||
if (key.shiftKey != ModifierKey::Disabled)
|
||||
{
|
||||
if (state.numpadKeyPressed[it->second])
|
||||
{
|
||||
//replace it with original numpad
|
||||
data->lParam->vkCode = it->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Helpers::IsNumpadKeyThatIsAffectedByShift(data->lParam->vkCode))
|
||||
{
|
||||
// store if the Numpad key was pressed or not. If numpad numbers were pressed but then we get the same key KEY UP but with Numpad unlocked we will replace it.
|
||||
state.numpadKeyPressed[data->lParam->vkCode] = (data->wParam == WM_KEYDOWN || data->wParam == WM_SYSKEYDOWN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace KeyboardEventHandlers
|
||||
@@ -42,6 +94,7 @@ namespace KeyboardEventHandlers
|
||||
// Check if the key event was generated by KeyboardManager to avoid remapping events generated by us.
|
||||
if (!GeneratedByKBM(data))
|
||||
{
|
||||
UpdateNumpadWithShift(data, state);
|
||||
const auto remapping = state.GetSingleKeyRemap(data->lParam->vkCode);
|
||||
if (remapping)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user