Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mouse simulation 1

Status
Not open for further replies.

Scilli

Technical User
Apr 4, 2006
8
0
0
IT
Hello,
is there a way to simulate mouse use in visual c++? I.e. how can I simulate the pression of the mouse left button on a window button(say buttonA), even if mouse pointer is far away from byttonA?
Thank you
 
What exactly do you want to do with it?

You can simulate a click by sending WM_LBUTTONDOWN and WM_LBUTTONUP.

Movement can be simulated with WM_MOUSEMOVE.

There are also CBT hooks which can be used to playback keyboard and mouse.
 
Thank you,
I have already tried with WM_LBUTTNDOWN, but I failed because WM_LBUTTONDONW send a message with the actual position of the mouse pointer.Instead I should simulate a click on position (x, y),say (40,10), even if mouse is an other position, say (300, 200).
 
Yes you do need all the info when you send a WM_LBUTTONDOWN. What I normally do is have a tracking flag. If that is on, it prints the message and everything that I think the message needs. That way you can simulate keyclicks and everything else. What you have to make sure is that there are appropriate delays in between the clicks and that the clicks are posted: not sent. Give the system a chance to respond to the click before you post the next operation.
 
I have already tried with WM_LBUTTNDOWN, but I failed because WM_LBUTTONDONW send a message with the actual position of the mouse pointer.Instead I should simulate a click on position (x, y),say (40,10), even if mouse is an other position, say (300, 200).

Actual mouse position coordinates you receive with real mouse messages. When you send simulated messages, fill coordinate fields by yourself with values you want, what actually is the problem?
 
I didn't know WM_LBUTTONDOWN had some fields!! How can I fill them?
 
Thanks,
so I have to write
WM_LBUTONDOWN LPARAM (40,10)?
 
Code:
PostMessage(button_handle, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(40, 10));
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top