If i be holding the CTRL key down while sending a PostMessage containing WM_KEYDOWN it 'mess' with the message.
I couldn't understand what really happens, if it sends CTRL plus the message being sent or what?
How to reproduce:
Launch notepad and hold the CTRL key while the code is running
#include <windows.h>
#include <iostream>
struct extraKeyInfo
{
unsigned short repeatCount;
unsigned char scanCode;
bool extendedKey, prevKeyState, transitionState;
operator unsigned int()
{
return repeatCount | (scanCode << 16) | (extendedKey << 24) |
(prevKeyState << 30) | (transitionState << 31);
}
};
int _tmain(int argc, _TCHAR* argv[])
{
auto hwnd = FindWindow(0, L"Untitled - Notepad");
HWND hEdit = FindWindowEx(hwnd, NULL, TEXT("Edit"), NULL);
for (char ch = 'a'; ch <= 'z'; ch++) // Output a-z in Notepad
{
short vkCode = LOBYTE(VkKeyScan(ch));
extraKeyInfo lParam = {};
lParam.scanCode = MapVirtualKey(vkCode, MAPVK_VK_TO_VSC);
PostMessage(hEdit, WM_KEYDOWN, vkCode, lParam);
lParam.repeatCount = 1;
lParam.prevKeyState = true;
lParam.transitionState = true;
PostMessage(hEdit, WM_KEYUP, vkCode, lParam);
Sleep(200);
}
}
Is possible somehow to send just the desired key into the PostMessage independent if i have any keydown?