Archived

This topic is now archived and is closed to further replies.

More accurate mouse detection

This topic is 6154 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I recently wrote a programming to teach me a little more about Win32 and GDI and I developed a little program that puts a 6x6 square (basically a big pixel) around the center where the mouse pointer is when you press the button, but when I move the mouse too fast it seems to only log every 10-20 mouse movements so I have gaps in my line... // this is generic because I haven''t memorized it all, but // should be readable case WM_MOUSEMOVE: { if (fKey == LBUTTON) { SetPixel(hdc, mouseX, mouseY); } } Is there a better way to search for mouse movements? OMG let there be a better way (it works in MSPAINT!) -Sponge99

Share this post


Link to post
Share on other sites
MS Paint simply draws a straight line between the current mouse position and previous mouse position. The gaps are due to the update rate of the mouse. Stare at a point on your monitor and move the mouse quickly back and forth over that spot. You will see that the mouse movement is not a smooth curve, but a series of large jumps.

Steve ''Sly'' Williams  Code Monkey  Krome Studios

Share this post


Link to post
Share on other sites
Yeah, I knew that''s the problem I have: the mouse isn''t as smooth as it should be...but in the Paint window, your mouse IS very smooth, how did they do that? Would it require low level programming? Or just trap more messages?

Share this post


Link to post
Share on other sites
Actually, Sponge, your mouse is as smooth as it gets. MSPaint, PSP, PhotoShop, or any paint package do not use any different mouse functions than you are using. They simply use a different method of drawing, as Sly pointed out. You need to draw a line from the last mouse position to the current mouse position. That way, when the mouse skips, you don''t get skips in your drawing.

If I''m not mistaken most programming books for the visual toolsets (VB, MSVC, Builder, Delphi) all have simple paint program examples. You might try looking in one of these books to get a better idea.

Micah

Share this post


Link to post
Share on other sites
it looks like you may not want the WM_MOUSEMOVE message to handle the mouse movement because WM_MOUSEMOVE is checked based on a fixed timer.

You may instead use WM_TIMER message, and set a timer with very high frequency, then have GetCurorPos to retrive the mouse position.


Hope this helps.

Share this post


Link to post
Share on other sites
Both those ideas sound both interest me very much. Especially the WM_TIMER one...great idea. Didn''t think about that at all but it makes sense now that I think about it...I guess I have to go try it out now (oh the debugging pain!)

-Sponge99

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
WM_TIMER is THE lowest level message in message handling. It does
not even go to the message que but it will only set a flag in message handler. Only when all the other messages are handled in
message que the system will check if the timer flag was on and
then call the handler. So i think you should stick to the mouse move message.
The best way to draw is not to draw at all! At least not in a mouse move handler. Just save the coordinates to an array and draw the array in timer handler at once. Of course
the drawing will be a bit behind of mouse but it will catch up after you stop moving it.

Share this post


Link to post
Share on other sites
You might be able to use GetAsyncKeyState, I'm not sure if it only tells you button states, or if you can get the position.

Magmai Kai Holmlor
- The disgruntled & disillusioned

...
Post you're msg pump (unless you're using MFC, then just say so)

Edited by - Magmai Kai Holmlor on February 6, 2001 11:49:02 PM

Share this post


Link to post
Share on other sites
You could always just "hack" into the mouses interrupt, but that''s more of a low-level DOS thing

OR you can get an optical mouse, they''re even more accurate and smooth than you''re little ball mouse. AND they don''t get dusty

Share this post


Link to post
Share on other sites
Actually, hacking the mouse interrupts sounds fun..but I remember writing my first (and only, hehe) game for DOS, and when it came time to the keyboard handler, I bought books and read and read, and then I cut and pasted off of an internet site. That shows how strong I am.

BTW, I used the line thing, where you draw a line from prev_point to current_point. Works quite nice now. The WM_TIMER thing was weird so I opted out. I sat down and said "Timer or line?" and line was much easier to do, in my opinion.

I have an optical mouse, but not everyone does, and there not THAT accurate...

Finally, where can I look up info on VxD''s? Virtual device drivers, right? Didn''t Win2k oust those? Geez, Windows should alow a namespace of LOWLEVEL where you can do low-level stuff freely and the compiler/OS doesn''t care.

That was alot, thanks alot though
-Sponge99

Share this post


Link to post
Share on other sites