   DXInput and Mouse position!
  Hey, I''m using DirectInput (in C#) to get feedback from the mouse, I know there are two methods of feedback, Absolute and non-Absolute, one gives the difference in x,y that the mouse has moved since it was last checked, the other gives its position in an x,y plane. Now, I have come across a problem, how do you track /where/ the mouse is on screen, for instance I want to know if the mouse is at position (1,5) on my applications window or any position for that matter, am I being really stupid about this? Its just that when using absolute values u are given some large number to start with and if you keep moving the mouse in any direction, when it reaches the edge of the screen the cursor stops moving but the values keep going, so using the absolute values for tracking the mouses'' position is a no-go. Obviosuly non-absolute values don''t work either as they suffer from the same problem.Thanks for your help,Chris 
  Anyone ;  I am hardly an expert, so don''t take this as pretentious, but couldn''t you just have the program consider anything past a the right side of the screen to be no higher than the right side of the screen, etc? Just have your program itself bound the mouse in. You are probably looking for a more elegant, specific solution but that occured to me reading your post. Basically all I''m saying is just have your program track the mouse location by hand and use the since last checked method to track it, and set your own borders. ;  I''m working on my direct input wrapper at the moment and I''m having a similar problem.  I''m thinking there may not be a pure DirectX solution to getting the position of the cursor that people see on the screen, because that position is set by windows, not the hardware that direct input is reading directly from.At the moment I''m leaning towards getting the mouse position through other methods, and then keeping track of the position manually by adding the difference in position that relative mode gives you.If anyone else has a solution, I''d like to hear it too. ;  hehe, I''m sure someone must have come across this before  at the moment i''m trying to store the location of the mouse using X and Y then add the difference that DirectInput gives you, but I''m having issues like how to set the initial position of the cursor and handling if the cursor goes off the edge on the window.Any experts out there that can lend the us some advice ;  koniosis, how did you get direct input to go into absolute mode for the mouse?  I've always just kept it in the default relative mode.  I looked through the direct input mouse sample and the help at MSDN and as far as I can tell you have to use EnumObjects and then when it finds an axis, use SetProperty to make that axis DIPROPAXISMODE_ABS, but I'm haveing a hell of a time with the syntax of it all.  If you help me put it in abolute mode, maybe I can figure out a better way after playing around with it for a while  Edit:  Ok, this seems kinda strange but I set my program up to obtain the position of the mouse at startup using GetCursorPos and then track the relative changes using direct input and if you move the mouse around, it will easily get out of sync with the windows cursor just moving it around and not even touching the edges of the screen. I've come to the conclusion, that if you want to use the windows cursor, just use GetCursorPos... if you want a direct input based GUI, make your own cursor and render it yourself, then you have no problem figuring out where it is.   [edited by - Subconscious on February 15, 2004 9:17:59 PM];  im using C# Managed DirectX, so to setup the mouse in Absolute mode is just a case of: device = new Device(SystemGuid.Mouse);device.SetCooperativeLevel(null, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive)device.Properties.AxisModeAbsolute = true;device.Aquire();I'm guessing drawing ur own cursor is the only way to go then. though It shouldn't get out of sync from inside ur window should it?   [edited by - koniosis on February 15, 2004 9:30:47 PM];  I think drawing your own cursor is definitely the way to go, just set up the mouse in Exclusive mode and there will be no windows mouse pointer, just draw your own and move its position as the direct input data comes in and don''t let it go beyond the bounds of the screen and you won''t have to worry about sync problems. ;  ah, well that would be ok, but i hate it when games steal ur cursor, anyway i found this for .net users:http://www.dotnetforums.net/t78283.htmlit basically describes how the guy uses a mixture of windows and DXInput, which is what i've done now, heres what i've got: /* This is placed in the mouse state changed code thingy  renderTarget is a System.Windows.Control that the scene is being renderd to (basically the window)*/mousePosition =  renderTarget.PointToClient(System.Windows.Forms.Cursor.Position);I don't know how easy that is to convert to C++.Also for full screen mode drawing ur own cursor goes without saying, as u'll probably want to be doing it in exclusive mode. I've got multiple monitors so non-exlusive in full screen will lead to the mouse appearing on the other monitors if the user moves the mouse too far (Not cool).   [edited by - koniosis on February 15, 2004 10:03:36 PM];  Adding to my previous post, for those interested, it seems that when you are running in Windowed mode (and you don't want exclusive access to the mouse) you should you the "mousePosition =  renderTarget.PointToClient(System.Windows.Forms.Cursor.Position)" but when in full screen mode, take exclusive access and draw the cursor urself and DO NOT call the Forms.Cursor function as it WILL slow things down, accessing windows APIs (thru the framework) will slow things down as you are no longer talking directly the hardware but going through windows, so shove an if statement in. Another solution is that when in window mode, take exclusive access and draw the mouse urself and then when the user wants to use the mouse elsewhere allow them to press say Escape and relinquish exclusive mode until the user clicks the window again (or it gets focus?).Example: /* Mouse state is the DirectInput object that lets you access the state of the mouse, I'm assuming you're not in absolute mode,so you will be recieving the amount the mouse has moved since you last checked. Also this is semi-C# Pseudo code so it won'tactually work. OnStateChange gets called whenever the state ofthe mouse changes, alternativley you can check the mouse statemanually during your render pump.*/OnMouseStateChange(MouseState mouseState){ if (!fullscreen) // We're in windowed mode {   mousePosition =  renderTarget.PointToClient(System.Windows.Forms.Cursor.Position); } else // We are fullscreen so keep track of the cursor ourself {   mousePosition.X += mouseState.X;   mousePosition.Y += mouseState.Y;   if (mousePosition.X > Width) mousePosition.X = Width;   if (mousePosition.X < 0) mousePosition.X = 0;   if (mousePosition.Y > Height) mousePosition.Y = Height;   if (mousePosition.Y < 0) mousePosition.Y = 0; }}  [edited by - koniosis on February 17, 2004 10:54:11 AM] [edited by - koniosis on February 17, 2004 10:55:04 AM]