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?
jkrConnect With a Mentor Commented:
>>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!
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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

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?
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.

All Courses

From novice to tech pro — start learning today.