Need a way to find a faster mouse position update

Using win32 api. First I used WM_MOUSEMOVE until I found it is probably the slowest way to pick the position of the mouse.

Next I used this:
1
2
3
4
5
6
7
8
void cWinApp::aFindMousePos()
{
	static POINT			Pt;
	GetCursorPos(&Pt);

	m_aMousePos.x = Pt.x - m_aWinInfo.rcClient.left;
	m_aMousePos.y = Pt.y - m_aWinInfo.rcClient.top;
}


I found this from GameDev that offered two different ways of a higher accuracy mouse position. One was GetCursorPos the other was DirectInput. Since I don't want to download and install directX just to use a mouse feature I decided to go with GetCursorPos which finds the absolute mouse position on the screen (hence why I'm subtracting by client position to find the relative position on my winclient).

I was pretty happy until I made my own scroll bar (I know the API provides a way to add a scrollbar object, but I went and made my own) and I found that if I move my mouse really fast, the bar cannot keep up to the position of my mouse.

Basically what it looks like is the object is 1 position behind the current position of the mouse. Does anyone know a way to fix this?
You should be aligning the centre of your scroll bar to the mouse. This way it doesn't matter how fast the mouse moves the scroll bar will always fix itself to the centre of it.

This behavior is quite standard. If you click down on a scroll bar on a lot of applications then move off the application the mouse will not longer make the bar move. Move back onto the app and the scroll-bar will be centered under your mouse cursor.

If your trying to find a way to get the mouse quicker. Thats going to consume excess resources that are not actually required to achieve acceptable results.

In game programming, we put our application into a 100% utilization message loop. This allows us to check the position of our mouse many times per-second, but we are using a lot of CPU to have such a high turnover.

What you are describing doesn't relate to how fast the mouse update is done, but how fast your application is doing it. IMO. center the scroll bar under your mouse cursor on every update.
Even though it isn't a game, it utilizes many flash-like UI that require precise mouse overs (mainly due to timing and effect of 'hovering' a mouse over sensitive areas, I used the scroll bar example for illustration)

I tried what you said before and the lag was still clearly detectable. I think it is something only to do with win32 client since I don't recall having this sort of problem with directx. I could cut everything out of my program except an image manager whose only job is to keep an image posted at the cursor position passed into my app and the image will always be 'following' the cursor, its just more obvious the faster someone moves the mouse. Even if the image position was shifted so the cursor was always in the center of the img, this effect would still happen. However upon looking at the win32 resource objects, this doesn't happen at all. IE click the top of a window and move it at the corner, the window is always precisely at the position of the cursor.

My last option would be to make the mouse cursor invisible and use my own cursor class (which would be like place a image to the same exact position...not hard or excessively difficult) which would update exactly like how the rest of my app is being updated with the same 'slightly in the past mouse position' and thus everything will look in sync.

I didn't want to do it that way - sigh..
Hmm.

Have you thought about using a Peek/GetMessage() loop. I'd have to check which one is better for application development. It'd basically give your application a message everytime one hits the queue. This can be used for small game dev because it won't consume 100% CPU. The other one uses 100% CPU.
I did use GetMessage until I found that it is blocking. I recall actually seeing for sure it if is (testing confirmed it) however msdn library doesn't mention anything about being a blocking call. I thought that was pretty lame.

I use peek, but keep all of my calls that need to be called every iteration outside winproc since the only time it would go into that is if there is something on the queue. If there was no set timer then the most common message would be wm_mousemove.

I tried to disable my mouse but on first pass I couldn't. Anything I researched either was about changing the mouse or completely disabling it altogether which isn't what I want. I still want the mouse functional except I just don't want to be able to see it.
I will get my code from my 3D work when I get home tonight and post it for you. It's used in a 3D Engine.
Ok thanks.

What is it written in? I can only understand native, directx and opengl stuff.
Last edited on
It's developed in C++. Sorry I haven't posted it yet, I have been unable to post during the forum changes =\ Weird things
Topic archived. No new replies allowed.