Home > Windows API > How to get mouse movement history?

How to get mouse movement history?

The GetMouseMovePointsEx function retrieves a history of up to 64 previous coordinates of the mouse or pen.

Here is a demo that replays our mouse movements…

void ReplayMouseMovements()
{
   // Current cursor position
   POINT ptCurrentPoint = { 0 };
   GetCursorPos( &ptCurrentPoint );

   // Record marker, mouse co-ordinates prior(and including) to this point is returned in
   // the recorded array of points
   MOUSEMOVEPOINT mmpSamplePoint = { 0 };
   mmpSamplePoint.x = ptCurrentPoint.x;
   mmpSamplePoint.y = ptCurrentPoint.y;

   // Count of records expected, MSDN says max points returned will be 64
// Anything greater than 64 results in error, API returns -1
   const DWORD dwMaxPoints = 64;

   // On return from function will hold last recorded mouse movements
   MOUSEMOVEPOINT mmpRecordedMovements[dwMaxPoints] = { 0 };
   const DWORD dwMode = GMMP_USE_DISPLAY_POINTS;

   // Get all points prior to sample point
   const int nPtCount = GetMouseMovePointsEx( sizeof( mmpSamplePoint ),
&mmpSamplePoint,
mmpRecordedMovements,
dwMaxPoints ,
dwMode ) ;

   // Loop through and animate
   for (int nIndex = 0; nIndex < nPtCount; nIndex++)    {       SetCursorPos( mmpRecordedMovements[nIndex].x, mmpRecordedMovements[nIndex].y );       Sleep( 80 );    } }// End ReplayMouseMovements[/sourcecode]

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: