Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Simulate Mouse move / clic from a C++ app

142 views
Skip to first unread message

Benoît Touron

unread,
Aug 18, 2003, 9:40:35 AM8/18/03
to
Hello there !

How can I simulate a mouse move, and then clic from a C++ app ?

I have an external app, with a graphical area. I need to move the mouse
to a specific location within this window, then clic and enter some text.
The goal is to drive this external app from my own app.

I have the handle of the main window, but I am not able to move the
mouse with a program.
Does anyone know how to do this ? Which system call do I have to use ?

Thanks
Ben

Bjarne Nielsen

unread,
Aug 18, 2003, 10:00:00 AM8/18/03
to
I haven't tried it, but did you look at the SetCursorPos() function??

--
Cheers
Bjarne Nielsen

"Benoît Touron" <b.to...@citb.bull.net> skrev i en meddelelse
news:e6tCq1YZ...@TK2MSFTNGP09.phx.gbl...

Benoît Touron

unread,
Aug 18, 2003, 11:56:20 AM8/18/03
to
Bjarne Nielsen wrote:

> I haven't tried it, but did you look at the SetCursorPos() function??
>

Thanks Bjarne.
It works ! But I am still not able to simulate a mouse clic
in a specific location ot the windows client area.
I tried the following:

HWND other=::FindWindow(NULL,"CHILD WINDOW");

::SetWindowPos(other,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE|SWP_SHOWWINDOW);
SetCursorPos(10,10);

::SendMessage(other,WM_LBUTTONDOWN,MK_LBUTTON,0x0A0A);
::SendMessage(other,WM_LBUTTONUP,MK_LBUTTON,0x0A0A);

The window actually moves to the top left corner of the screen. This
should pop-up the system menu (because the mouse is at the right
location), but nothing happens.

Any other (good) idea ?

Thanks a lot anyway.
Ben

Bjarne Nielsen

unread,
Aug 18, 2003, 12:59:52 PM8/18/03
to
Like I mentioned before, I haven't really done this before. I did something
similar once, but that code is gone now :-(
I think the position parameters are wrong, though. The LPARAM should contain
the X and Y coordinates in low and high order WORDs, but you packed then
together as two BYTEs in one WORD, so I gues it should be 0x000a000a
instead, or more correctly MAKELPARAM(0x0a, 0x0a).
Also, you shouldn't hard-code the coordinates (as you probably know), but
for testing it's ok.

--
Cheers
Bjarne Nielsen

"Benoît Touron" <b.to...@citb.bull.net> skrev i en meddelelse

news:%23Vo$eBaZDH...@TK2MSFTNGP10.phx.gbl...

0 new messages