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

DirectInput using Managed DirectX

Started by SectoR- Jun 26, 2005 at 3:36 PM 3 replies 400+ views
Original Post
SectoR-
SectoR-
Hi, I'm trying to get the mouse coordinates from inside a window using DirectInput. As most of you probably know DirectInput only returns how much the mouse has moved since the last time it checked. I've tryed to use windows forms messaging to get the starting position of the mouse by binding a OnMouseMove event on the form and make it run this code:

		private void Form1_MouseMove(object sender, MouseEventArgs e)
		{
			xPos = e.X;
			yPos = e.Y;

			this.MouseMove -= new MouseEventHandler(Form1_MouseMove);
		}

So it just gets the position once and then unbinds itself and then I let DirectInput update the values in xPos and yPos. This method does not work, first of all it's rather inaccurate most of the time and second DirectInput keeps feeding the program the mouse movement even when it's placed outside of the form. Does anyone know how to use DirectInput to get 'normal' mouse coordinates inside a window ( the top left corner should be position 0,0 ) ? Or should I just stick to windows events ? Thanks in advance.
moogleii
moogleii
Yeah i'm having the same problem.

You can set the mouse into absolute mode, but for whatever reason, the coordinates it returns are HUGE (in the billions range). Movement of the mouse thereafter seems to only change the position at most by the thousands, so it's utterly worthless to me like that.

mouse = new DirectInput.Device(SystemGuid.Mouse); mouse.Properties.AxisModeAbsolute = true;

The default relative mode seems only handy for FPS?
Bulma
Bulma
If you need mouse for windows handling (buttons, etc...) use standard window events. For custom GUI, you can use DInput, but then you should draw "cursor" and handle events youself...
You can also mix both, for example, I used windows events for getting absolute mouse X, Y coordinates, and DInput for getting mouse button states (left/right button).
Bulma
GroZZleR
GroZZleR
Remove absolute mode and track it for yourself.

Some init code:
int x = 0, y = 0;

Mouse update:
x += state.X;
y += state.Y;

if(x < 0) x = 0;
if(y < 0) y = 0;
if(x >= ScreenWidth) x = ScreenWidth
if(y >= ScreenHeight) y = ScreenHeight;

DrawCursor(x, y);
moogleii
moogleii
Quote:
Original post by GroZZleR
Remove absolute mode and track it for yourself.


Hmm that seems like a pretty good idea. One caveat, and maybe you have an answer, but wouldn't the coordinates be off initially until you run the cursor off the screen?

For example, in relative mode, the moment you start your app, wherever the mouse happens to be is where DX sets as (0,0). So with your example, "calibration" won't really occur until a user mouses over to one of the edges. Any ideas for a workaround?

Topic Locked

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

Sign in to reply to this topic.