sending mousedown and mouseup to foreign application

  • Thread starter Thread starter Trollpower
  • Start date Start date
T

Trollpower

Dear NG,

ive got a small C# Application which needs to send a mousedown event,
followed by a mouseup event to a foreign window (eg. browser window).

I managed to get the appropriate windowhandle and also putting it into
the foreground. But sending a message with "buttondown" allways shows
no effect. I dont get any error-messages, since i put the whole code
into a try-catch-clause.

I use the following code to send a mousedown-message to the window:

uint WM_LBUTTONDOWN = 0x0201;
SetForegroundWindow((int)windowHandle);
SendMessage(windowHandle, WM_LBUTTONDOWN, 0, 0);

The "windowHandle"-variable is valid and "SetForegroundWindow" show
effect. i also tried PostMessage instead of Sendmessage, but the
effect stays the same: nothing happens.

Background:

The target window shows a small game, which needs a mouseclick to be
started. The window shows up but the sendmessage wont let the game
start.

Any ideas on how to bring the sendmessage to work?

Thanks in advance

Jens
 
Gabriele G. Ponti said:
Try setting the wParam of SendMessage() to MK_LBUTTON.

Thanks Gabriele,

i tried your suggestion without any success. Anyone got further hints
on how to solve this problem?
 
Thanks Gabriele,

i tried your suggestion without any success. Anyone got further hints
on how to solve this problem?

I've never had a lot of success sending dummy mouse clicks to
other windows, I think that Windows knows where the mouse is and
just doesn't accept that it was clicked.

The help says that lParam should contain the mouse co-ordinates,
does 0 make sense in your app?

Do you need to send a mouse click, could you use a different
message, perhaps a user registered message?
 
Thanks Jeff for your answer,

i allready tried to submit the mouse-click.coordinates. But i had no
luck. The Game runs in a small explorer window which only needs a
mouseclick to start. The coordinates are not important.

But meanwhile i solved the problem with a small workaround.

First i put the window to foreground (SetForegroundWindow), then i move
the mousecursor over the window (eg. Cursor.Current = new
Point(100,100);) and as a last thing i call SendMessage with a
mouseclick as messagetype and also the coordinates.

This is quite an afford to let a foreign application accept a mousclick.
But now it works acceptable.

Thanks for anybodys help on this issue.

Greetz

Jens
 
Back
Top