Skip to main content
gamedev.net
🔒 Locked

[.net] Direct Input Mouse Problems

Started by Peter Conti 0 replies 850+ views
Original Post
Peter Conti
Peter Conti
Hi, With DX8 and C++ I never had any problem using the mouse in both absolute mode and not absolute modes but with DX9 and .NET I have problems, I cant get either to work correctly. I am having trouble mapping the mouse to the screen. This is the closet I have it to working but it still is a bit un-accurate. Also how can I hide the mouse cursor from diplay so that I can use a sprite in its place. (That might help me solve the initial prob) public void InitializeInput() { // Create our mouse device deviceM = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Mouse); deviceM.SetCooperativeLevel(this, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive); deviceM.Properties.AxisModeAbsolute = false; deviceM.Acquire(); //get initial state (at least I assume) mx = SCREEN_WIDTH/2; my = SCREEN_HEIGHT/2; } then private void UpdateInputStateM() { // Check the mouse state MouseState state = deviceM.CurrentMouseState; // Buttons byte[] buttons = state.GetMouseButtons(); // string mouseState = "Using CurrentMouseState: \r\n"; mouseState = "Using CurrentMouseState: \r\n"; // state. mx += state.X; my += state.Y; if (mx < 0) mx = 0; if (mx > 800) //oh 800 is the screen width and 600 is the height mx = 800; if (my < 0) my = 0; if (my > 600) my = 600; mxB = mx; myB = my; if (mxB > 800) mxB = 800; if (mxB < 0) mxB = 0; if (myB > 600) myB = 600; if (myB < 0) myB = 0; // Current location of the mouse mouseState += string.Format("{0}x{1}x{2} mxb {3} myb {4}\r\n", mx, my, state.Z, mxB, myB); for (int i = 0; i < buttons.Length; i++) mouseState += string.Format("Button {0} {1}\r\n", i, buttons != 0 ? "Pressed" : "Not Pressed"); } which is called on every on paint loop. If anyone can help it would be great.
Peter Conti
Peter Conti
Thanks to all those who had a look at my post.
Fortunately for me I solved the problem by working out how to hide the mouse cursor cursor.Hide() and then using a custom bitmap that uses the mBx and mBy values.

Topic Locked

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

Sign in to reply to this topic.