I am trying to send a keystroke to another window via PostMessage. I can successfully run WM_KEYDOWN without my program crashing, but the other 3 messages fail.
As of now I'm sending 'a' to the other program. (0x00021e0*)
Code:
#define SETBITS(var,mask) (var |= mask)
#define CLEARBITS(var,mask) (var &= ~mask)
#define CHKBITS(var,mask) ((var&mask) == mask)
...
void SendKey(char input)
{
LPARAM lParam;
short key = VkKeyScan(input);
UINT scancode = MapVirtualKey(key, 0);
SETBITS(lParam,0x00021e00);
PostMessage(lWnd, WM_KEYDOWN, key, lParam);
Sleep(10);
SETBITS(lParam,0x00021e02);
PostMessage(lWnd, WM_CHAR, key, lParam);
Sleep(10);
SETBITS(lParam,0x00021e03);
PostMessage(lWnd, WM_KEYUP, key, lParam);
Sleep(10);
}
I created 0x00021e0* from the API documentation, but like I said the last 3 are failing.
Code:
29
Specifies the context code. The value is 1 if the ALT key is held down while the key is pressed; otherwise, the value is 0.
30
Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is 0 if the key is up.
31
Specifies the transition state. The value is 1 if the key is being released, or it is 0 if the key is being pressed.
So the first PostMessage() is obviously 0000. The second one that is not working is 0010, and the third is 0011.
Help?