Jump to content
  • Advertisement
Sign in to follow this  
Aidamina

DirectInput MouseState (Solved)

This topic is 4728 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Whenever i use MouseState.X/Y/Z It says they are zero. Any suggestion? I'm running this in a fullscreen Direct3d App Thx, Aidamina Loads Mouse:
mouse = new Device(SystemGuid.Mouse);
if(mouse == null)				
p_Mainclass.AddOutput("Input Device Error: "+"No mouse found.");
mouse.SetCooperativeLevel(this.p_Mainclass.p_Window, CooperativeLevelFlags.Foreground | CooperativeLevelFlags.Exclusive);
mouse.Acquire();
Gets Mouse coordinats to string:
public string GetMouseStatus()
{
if (mouse==null)
return "ERROR NO MOUSE FOUND";
MouseState mousestate= 	mouse.CurrentMouseState;
string Output = "Mouse Postion (x/y): "+mousestate.X+"/"+mousestate.Y+"\n ScrollState: "+mousestate.Z+"\n";			
return Output;
}
[Edited by - Aidamina on December 31, 2005 7:41:22 AM]

Share this post


Link to post
Share on other sites
Advertisement
The Mouse in DirectInput uses Relative positioning. It's position is directly related to it's last position. So if you start it and the cursor is at say, 120x120, but you're not moving the mouse, you're going to see (0, 0) for the coords. If you move the mouse you might see somethign like (-5, -10).

What you have to do is something similar to this:

global_x += MouseState.x;
global_y += MouseState.y;


That'll help get an Absolute position system going. But it'll still be relative to where the cursor started. The DirectInput mouse system is annoying at times for 2D type stuff.

Share this post


Link to post
Share on other sites
I don't know much about managed DirectX, but in C++ you would do something like the following to get "Absolute" coordinates. The problem is it's still related to where the mouse was first initialized.

DIPROPDWORD dipdw;
HRESULT hr;
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
dipdw.dwData = DIPROPAXISMODE_ABS;
hr = lpdiDevice->SetProperty(DIPROP_AXISMODE, &dipdw.diph);


Basicly, all the above does is instead of adding the relative positions yourself, DirectInput does it for you. It's still exactly the same thing.

Share this post


Link to post
Share on other sites
Thank you for pointing to the right direction:

Code that solved it:



[DllImport("user32.dll")]
static extern bool GetCursorPos(ref System.Drawing.Point lpPoint);



And

System.Drawing.Point p = new System.Drawing.Point(); ;
GetCursorPos(ref p);




After that you can use p.X and p.Y to get the screen coordinats
I'm using a fullscreen application, so im not sure if it will work on Windowed mode.

Share this post


Link to post
Share on other sites
Just be careful when using that if you plan on rendering your own cursor graphic. There will be a pause between the cursor moving on your screen and when you actually move it.

I was trying to avoid going that route, but it's probably unavoidable at this point if you really need very exact coordinates.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!