2

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)

postmessage 1 postmessage 2 postmessage 3 postmessage 4

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);
        }

code

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!) [postmessage 1 postmessage 2

SSpoke
  • 5,656
  • 10
  • 72
  • 124
  • If I recall correctly, an antivirus might be blocking the usage of this function to prevent keyloggers. The code appears fine.. Do you have ZoneAlarm, Avira or anything like that? – Saustin Dec 30 '13 at 00:09
  • What makes you think the target process accepts input of that form. Tell us about the target process. What is it? Is it running at a higher integrity level? Why don't you use the automation interface? – David Heffernan Dec 30 '13 at 00:11
  • Have you tried sending `WM_CHAR`? Generally the `WM_KEYDOWN/WM_KEYUP` messages are traslated to `WM_CHAR` by `TranslateMessage` and not processed in the message loop at all. – Retired Ninja Dec 30 '13 at 00:22
  • You might also have more success with [SendInput](http://msdn.microsoft.com/en-us/library/ms646310%28v=vs.85%29.aspx) – Retired Ninja Dec 30 '13 at 00:29
  • No anti-virus the game does use `DirectDraw` which I assume uses `DirectInput` as well. – SSpoke Dec 30 '13 at 00:40
  • @RetiredNinja I will try `WM_CHAR` Edit: can't figure out the lParam for VK_RIGHT VK_LEFT for `WM_CHAR`, But trying the same `lParam` as the `WM_KEYDOWN/WM_KEYUP` still does nothing. I will try `SendInput` – SSpoke Dec 30 '13 at 00:41
  • [You can't simulate keyboard input with PostMessage](http://blogs.msdn.com/b/oldnewthing/archive/2005/05/30/423202.aspx). You can fake the message, but you can't fake the other environmental conditions. – Raymond Chen Dec 30 '13 at 00:47
  • `SendInput` doesn't seem to work, it works on Notepad, but inside the game, those `VK_LEFT` `VK_RIGHT` don't do anything. I also tried `DIKEYBOARD_LEFT` and `DIKEYBOARD_RIGHT` which is suppose to work for DirectInput games but also doesn't work I also looped all examples 1000 times still nothing. – SSpoke Dec 30 '13 at 02:46

1 Answers1

1

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.

lion
  • 88
  • 5