I'm attempting to press the Left arrow key button and Right arrow key button.
The Window Handle I'm passing in is correct. (see screenshot below)
I used Microsoft Spy++ to figure out the correct PostMessage when I press Left/Right keys.
Here are the screenshots showing the lParam
and WParam
First 2 screenshots are VK_RIGHT
(WM_KEYDOWN
& WM_KEYUP
)
Next 2 screenshots are VK_LEFT
(WM_KEYDOWN
& WM_KEYUP
)
Here is the code I attempted to use it works by pressing NUMPAD1,2,3
to test out whether or not the VK_LEFT
OR VK_RIGHT
works.. (none of them work).
gKey(VK_NUMPAD1) //crap testing
{
windowHandle = FindWindow(L"SSClientMainWndClass", NULL);
printf("window handle = %x\n", windowHandle);
PostMessage(windowHandle, WM_KEYDOWN, VK_RIGHT, 0x414D0001);
//Sleep(1000);
PostMessage(windowHandle, WM_KEYUP, VK_RIGHT, 0xC14D0001);
Sleep(1000);
}
gKey(VK_NUMPAD2) //crap testing
{
windowHandle = FindWindow(L"SSClientMainWndClass", NULL);
printf("window handle = %x\n", windowHandle);
PostMessage(windowHandle, WM_KEYDOWN, VK_LEFT, 0x414B0001);
Sleep(1000);
PostMessage(windowHandle, WM_KEYUP, VK_LEFT, 0xC14B0001);
Sleep(1000);
}
Here are the screenshots of pressing the VK_NUMPAD1
in the game. (The Post message is sent to the correct Window and the information seems correct!)
Maybe you need to run your program as administrator, you can't send input to a process more elevated than yours. I used
keybd_event()
and it always worked for me, with the mention that Home/End require KEYEVENTF_EXTENDEDKEY.I know this is old, but I was looking for something similar and saw this has no answer.