The best way is to use direct input. The easiest way is to use SetCursorPos to position the cursor to a default location (like the center of the screen) and then everytime you get a mouse move calculate the relative movement and call SetCursorPos again.
if you use WM_MOUSEMOVE (or how this message calls) in WndProc you get some nice effects( maybe thats the problem):
if WM_MOUSEMOVE set mouse to center of window(SetCursor(…)) after getting some deltas( positionchanges) you have done the half of your work, because this function sends after setting the mouse to center again the same message with reversed deltas ! 1st message + 2nd message = nothing changes
!to solve this skip every second message!
sometimes you call in your WM_MOUSEMOVE routine somthing else, that will cause, that you get correct deltas without skipping some messages!
Are you sure about this? I have never had this problem, although I use Delphi for my GUI work, and maybe it filters these out somehow (though I doubt it).
P.S. after thinking about, I dont even think WM_MOUSEMOVE sends relative movement, only absolute position. So I just check MSDN and confirmed…it does NOT send relative movement.
[This message has been edited by LordKronos (edited 05-08-2001).]
If you don’t want to use DirectInput, the mouse position command is :
mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_MOVE,(x65536)/screenwidth,(y65536)/screenheight,0L,0L);
If it can help …
Originally posted by T2k: if you use WM_MOUSEMOVE (or how this message calls) in WndProc you get some nice effects( maybe thats the problem):
if WM_MOUSEMOVE set mouse to center of window(SetCursor(…)) after getting some deltas( positionchanges) you have done the half of your work, because this function sends after setting the mouse to center again the same message with reversed deltas ! 1st message + 2nd message = nothing changes
!to solve this skip every second message!
hehe i ran into that a while ago. first i just done the skip every second message thing but now i use something like ie no more WM_MOUSEMOVE
main_loop()
{
// read input
if (using_directinput)
…
else
getCursorPos(…)
…
setcursorpos(middle of the screen)
}