Search code examples
c#controlslocationmouseclick-event

Click a button from another Application, emulating mouse + coords?


I have tried to click on the button using the follow:

private const int BN_CLICK = 0xF5;
private const uint WM_LBUTTONDOWN = 0x0201;
private const uint WM_LBUTTONUP = 0x0202;
SendMessage(sendButton, BN_CLICK, IntPtr.Zero, IntPtr.Zero);
SendMessage(sendButton, WM_LBUTTONDOWN, IntPtr.Zero, IntPtr.Zero);
SendMessage(sendButton, WM_LBUTTONUP, IntPtr.Zero, IntPtr.Zero);

All the above fail to click the button, so I was wondering about other alternatives I have or if it is possible to get the button location X and Y from it's handler ?

Suggestions, ideas would be really good.


Solution

  • After many tests using sendmessage I have resolved trying PostMessage which worked like a charm...

    PostMessage(mainControlChild, WM_KEYDOWN, (int)Keys.Return, 0);
    PostMessage(mainControlChild, WM_KEYUP, (int)Keys.Return, 0);
    

    Resolved my problem and sends it on background.