C++/Mouse Tracking
Expert: Eddie - 1/23/2008
QuestionHello,
I'm kind of a beginner to this sort of programming in C/C , I've only done a few introductory courses in college. I was wondering how I would go about writing a mouse tracking application for a windows XP machine using the bloodshed Dev C++ compiler.
What I basically need to do is to grab the x and y coordinates of the cursor every XX number of microseconds until I tell it to stop.
I've also never programmed win32 applications, so I was wondering if it was possible to run this from a console application.
AnswerHello Rodolphe, thank you for the question.
I think you would be better off making this a standard Win32 application. It should be pretty easy to do what you want to do. You can use the method GetTickCount() that returns the amount of milliseconds since the system started running to do your time tracking, and GetCursorPos, and SetCursorPos for mouse positioning.
Here is documentation from the MSDN:
GetTickCount()
http://msdn2.microsoft.com/en-us/library/ms724408.aspx
SetCursorPos()
http://msdn2.microsoft.com/en-us/library/ms648394.aspx
GetCursorPos()
http://msdn2.microsoft.com/en-us/library/ms648394.aspx
Here is some pseudocode:
// In your app
DWORD start = GetTickCount();
// do some stuff
DWORD end = GetTickCount();
if(end - start > 5) // 5 milliseconds later
{
POINT p;
GetCursorPos(&p)
cout << "The cursor x is: " << p.x << " and y is: " p.y;
}
That should point you in the right direction.
I hope this information was helpful.
- Eddie