0

I think title of this question is pretty clear.

        const int WM_KEYDOWN = 0x100;
        const int WM_KEYUP = 0x101;
        const int WM_SYSCOMMAND = 0x018;
        const int SC_CLOSE = 0x053;
        const int WM_MOUSEMOVE = 0x200;
        int WindowToFind = FindWindow(null, "Untitled - Paint");
        PostMessage(WindowToFind, WM_MOUSEMOVE, 400, 500);
        PostMessage(WindowToFind, WM_KEYDOWN, ((int)Keys.LButton), 0);
        PostMessage(WindowToFind, WM_KEYUP, ((int)Keys.LButton), 0);

above, is current code. which does NOT work.(however postmessage DOES post actual keys like if I want to press A, it does that. However it fails on mouse, or I fail)

I also must point out that I dont even know what does lparam actually, I just used to set it to null and wparam to key. Im not even sure if im supposed to use wm_mousemove because it looks like its to "receive" rather than actually setting location. Then I read Lparam should be set to contain both x and y like 500 * 0x10000 + 500, and wparam as 0 etc., it didnt help. Googling for other ways didnt help either. I really dont care about ways, I just want to press leftmouse, on another window without focus, on certain location.

sake
  • 1
  • 3
  • 1
    WM_KEYDOWN and WM_KEYUP are for keyboard events. You might want to try WM_LBUTTONUP and WM_LBUTTONDOWN? – Johan Jul 24 '12 at 15:31

1 Answers1

0

Perhaps you're looking for SendInput (P/Invoke)

The sample code at P/Invoke also shows how you can use FindWindow and SetForegroundWindow if you want to programatically give another window focus (unsure if that's what you are trying to accomplish).

Christopher Currens
  • 29,917
  • 5
  • 57
  • 77
  • You are true that im a bit lost here. I've also looked at sendinput and the problem with it is that, -as you have said-, it requires window to be visible/infront. I'm looking for more of a "lets do it in background" solution, without interfering with user. Since you seem to be experienced, may I ask, do you think there is a way to do what I just said ? If there is not maybe i should just go with sendinput. – sake Jul 24 '12 at 16:46
  • [This link](http://stackoverflow.com/a/1230643/721276) answers that question correctly. Can't be done reliably. Also, the comment Johan posted to the question is also correct, you need to use the WM_LBUTTONUP/DOWN messages for the mouse. – Christopher Currens Jul 24 '12 at 16:58
  • Many moments later, I fixed the problem by what johan said and ((int)Keys.LButton) puttin this as third parameter. – sake Jul 24 '12 at 21:09