You are here:

C++/Mouse Tracking



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.

Hello 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:




Here is some pseudocode:

// In your app
DWORD start = GetTickCount();

// do some stuff
DWORD end = GetTickCount();

if(end - start > 5) // 5 milliseconds later
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


All Answers

Answers by Expert:

Ask Experts




I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by I also know a good deal about graphics via OpenGL, and GUIs.


I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2017 All rights reserved.

[an error occurred while processing this directive]