Automating mouse events

Is there a method to record and replay mouse actions or events?  I try to build a demo program with pre-recorded mouse events.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vinayak KumbarSr Program ManagerCommented:

U can use send message function to that window with the mouse messages. like

this->SendMessage(WM_LBUTTONDOWN, 0, 0); //will send l button click for that class.

Or u want to send to mainframe class, then

CMainFrame *l_pMainFrm = (CMainFrame *)AfxGetMainWnd();
l_pMainFrm->SendMessage(WM_LBUTTONDOWN, 0, 0);

Like that. U can use PostMessage() function instead of SendMessage().

Try this out.

Take a lok at windows hooks, and especially the following:

 Installs a hook procedure that posts messages previously recorded by a WH_JOURNALRECORD hook procedure. For more information, see the JournalPlaybackProc hook procedure.
 Installs a hook procedure that records input messages posted to the system message queue. This hook is useful for recording macros. For more information, see the JournalRecordProc hook procedure."

The WH_CBT hook would also be an alternative.

All necessary information on this issue can be found at
tungleAuthor Commented:
I tried all that but they did not work.  Here is what I did:

1) I had a MDI with tool bars
2) I overrided the PreTranslateMessage (in CMainFrame) to capture the mouse's movements/actions via MSG and saved them in a file.
3) To replay them, I used SetTimer to replay the file with actual delay (using Sleep) between actions.
4) I move mouse pointer using SetCursorPos( x, y ) where x and y are coordinates in the recorded MSG.  I have to do this as the mouse does not move.
5) For each msg of WM_LBUTTONUP,  WM_LBUTTONDOWN, or any mouse actions, I do a SendMessage( msg, 0, 0 ).

The mouse moves, but the mouse click does not execute.  If I remove step 4, nothing works.

Any idea?
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

jkr's answer is the right solution for you.
Well, journal playbacks are the right way to have one application play mouse or keyboard messages into another application.

But tungle's second comment makes it sound like he's trying to play back mouse movements into the _same_ app. That seems odd.

..B ekiM
tungleAuthor Commented:
I solved the problem using journal playbacks as jkr suggested.  Thank you for all the help.  I do not know how to pass the points to jkr, but you deserve the points.  Thanks again.

>>I do not know how to pass the points
>>to jkr, but you deserve the points

Simply posting this as a 'blank' answer... Fine that I could help you!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.