How to get mouse movement regardless of the cursor position?

When getting mouse movement,
every method I've found gets the cursor positions in different times and compare them to get the movement.

But this way has a serious problem. When the cursor is at the boundary, say, the left boundary of the screen, and then the mouse moves to the left, this method would fail to detect the movement since the cursor cannot move left.

Is there anyway that I can detect the mouse movement input without caring the cursor coordinates? If I write it in pseudo code, it may look like this:

{
double delta_x, delta_y;
Start_Add_Up_The_Mouse_Movement();
Wait_0.05_Seconds();
Get_The_Totoal_Mouse_Movement_Since_Last_Starting_Adding_Up(&delta_x, &delta_y);
/* now the (delta_x, delta_y) vector is the mouse movement in the last 0.05 second. */
}


If any of you experts can help, I would be very thankful!

=========================================================

By the way, how do you usually learn this kind of programming technics?
I seldom found textbook helpful for a thorough beginner! Those authors seem to forget how beginners feel in getting started.

For example, when I just began to learn C few years ago, I read the texbook by Deitel. It's not so helpful because there are too much text explanations, and too few simple code examples! What a thorough beginner really need is actually some simple examples first, not so much explanations first! It's just like learning a new poker game, the quickest way is to watch how your friends play. Before you actually see the play, no matter how hard your friends are trying to explain the rules, you feel confused what they're talking about. Too abstract. But after watching the actual play, and then listening to the explanations by your friends, you learn the rule very easily.

When I was confused by the textbook, a friend recommend this site : "cplusplus.com". This site is so helpful! The library references give a simple code example for every function, I almost understand every function by these examples before reading the text explanations! Of course, the text explanations are important, they provide the details. But they only work after you have a correct rough idea about the function! Only after I'm a little experienced in C, I started to find the Deitel textbook helpful sometimes, when I'm looking for a certain issue in detail.

The experience in learning OpenGL is similar : when reading the OpenGL SuperBible, I feel like listening to a friend trying to explain a new poker game by words, which doesn't really work. So I read the actual OpenGL code written by the instructor of my college class, and compile it to see what do these codes do. This way makes me learn much faster than trying to understand the articles in the textbook.

But here's the problem: it's not always so easy to get example codes when learning a programming subject! The good quality of this site is rare among online tutorials, and I could get simple OpenGL codes only because I was taking a relevant class, but it's not so possible to take classes for all subjects I have to learn in the future.

When I'm trying to solve the mouse input problem I've just mentioned, the most I can do by Internet is to find the MSDN references. But the MSDN library references are much worse than the library references here, they have only text explanations, no code examples at all! I think this kind of references only help those who already have some basic ideas about Microsoft libraries. It's for them to check the details.

So how do you usually get started in a new programming subject? For example, a new programming language, a new huge library like OpenGL, or how to get the direct input of mouse and keyboard?

Thank you for reading this article! I would be very thankful if any experienced programmer could share its learning experience!
Last edited on
closed account (D80DSL3A)
It's good you have clearly identified a learning style which works for you.

I agree that looking things up at MSDN is difficult. I don't think it's meant as a place for beginners to learn from. It's a reference site intended primarily for professionals.

There are lots of sites focusing on game development.
You'll find more useful stuff on these sites tutorials, forums, etc...

About your mouse motion problem.
If you are handling input via the usual wndProc() callback function in a windows program, then I'm not sure what you can do.
Windows will cease placing messages on your programs message que when the mouse cursor is outside the client area.

You could try handling the WM_MOUSEMOVE message. These messages appear whenever the mouse moves (again, within the client area only).

This should give you an ability to detect mouse movement without having to subtract mouse coordinates.

PS If you move this thread to the Windows forum you might get more and better advice about the mouse motion.
Last edited on
Topic archived. No new replies allowed.