Skip to main content
gamedev.net
🔒 Locked

DirectInput questions

Started by slyprid Jun 2, 2006 at 11:17 AM 1 replies 550+ views
Original Post
slyprid
slyprid
I'm trying to implement a mouse using directinput but can't seem to get it to work. I'm trying to acquire a absolute position of the mouse on the screen so I can determine if my mouse is over a button and such for my GUI. Now the problem i'm running into is that even though my mouse is moving, its not updating my mouse position. Here is what I have.

static DIMOUSESTATE mousestate;
dimouse->Acquire();
dimouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mousestate);
if (dimouse->GetDeviceState(sizeof(mouse_state), &mouse_state) == DI_OK)
{
     MouseX += mousestate.lX;
     MouseY += mousestate.lY;
}

For some reason its just sitting at 0, and every once in a blue moon you will see a value pop up but go straight back to zero. Am I doing this wrong, or is there a better way to achieve the absolute value for mouse coordinates. Thanks for your time. Slyprid
Enosch
Enosch
Unless I am mistaken (which I happen every now and again to be), DInput mouse updates the x-y delta each frame. So it only gives you the amount in pixels that your mouse moved since last update. You will need to keep track of the current position in your app. Also, make sure that you aren't losing the device between frames.

- Enosch
slyprid
slyprid
So would I need to make sure I acquire it each frame than. If so are there any performance costs to doing it each frame. I understand the positioning of the mouse, its using relative positioning, thats why I was creating an absolute position by adding the value to a base position on the screen such as midscreen or 0,0.

Topic Locked

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

Sign in to reply to this topic.