I think your problem lied in here
input.ki.wVk = key; // <-- should be modifier
input.ki.wScan = MapVirtualKey(modifier, MAPVK_VK_TO_VSC);
input.ki.dwFlags = KEYEVENTF_KEYUP;
inputArray[3] = input;
Therefore your program didn't release the SHIFT key.