Skip to main content
GameDev.net gamedev.net
🔒 Locked

DIRECTINPUT: Finding Absolute Mouse Coordinates....

Started by fpsgamer May 19, 2006 at 7:18 PM 0 replies 2.8k views
Original Post
fpsgamer
fpsgamer
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?
Falken42
Falken42
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.