Sign in to follow this  
fpsgamer

DIRECTINPUT: Finding Absolute Mouse Coordinates....

Recommended Posts

I am having trouble resolving the absolute screen position of the cursor. Here is my setup of the DirectInput mouse device...it is currently set up in relative mode (only because I'm not sure how to set it up in absolute mode):
if (lpdi->CreateDevice(GUID_SysMouse, &lpdimouse, NULL)!=DI_OK)
   return(0);

// set cooperation level
if (lpdimouse->SetCooperativeLevel(main_window_handle, 
                       DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)!=DI_OK)
   return(0);

// set data format
if (lpdimouse->SetDataFormat(&c_dfDIMouse)!=DI_OK)
   return(0);

// acquire the mouse
if (lpdimouse->Acquire()!=DI_OK)
   return(0);






Then in my main event loop I poll the mouse and try to convert the relative coordinates to absolute coordinates:
mouse_x += mouse_state.lX; //initialized to screen_width/2;
mouse_y += mouse_state.lY; //initialized to screen_height/2;






I thought that would give me absolute cordinates but the values do not seem to be correct. For example, if i drag the cursor to the corner of the screen the position doesnt appear as (0,0). How can I easily obtain the absolute (x,y) position of the cursor?

Share this post


Link to post
Share on other sites
There is no direct way to get the absolute position of the mouse in DirectInput. You might want to try GetCursorPos instead.

Once you get the point from GetCursorPos, you need to shift it relative to the client area of your window (see GetWindowInfo), then clamp it to the size of your window.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this