Repository: microsoft/PowerToys
File: src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardEventHandlers.cpp (C++)

Code before:
    {
        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)
                        {
                            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::IsNumpadKey(data->lParam->vkCode))
        {

Review comment (suggestion):
```suggestion
                        if (key == VK_LSHIFT || key == VK_RSHIFT || key == VK_SHIFT)
```
There's also a global shift VK which we need to catch. I've tried without this change and if we map "Numpad 1" to "Shift" instead of "Shift (Left)" or "Shift (Right)" the issue persists. This change might fix it.

Code after:
    {
        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))
        {