Jump to content
  • Advertisement
Sign in to follow this  
Peter Conti

[.net] Direct Input Mouse Problems

This topic is 4390 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

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!