Jump to content
  • Advertisement
Sign in to follow this  
Mrs Kensington

[.net] Recreating DirectInput Mouse Control with SWF

This topic is 4464 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, I've read in a couple of places that Microsoft is planning to remove DirectInput from DirectX (and thus MDX / XDA) and that it is better to use windows messages / XInput for input unless you want to use things like force feedback. I've just started to play with input for my engine and I've managed to get the Keyboard part working fine using SWF functions. I am now trying to do the mouse side and have got it mostly working but am having trouble with one section. I can happily get the distance the mouse has moved since the last update (I'm not worrying about pressed buttons yet as that should be easy). I've hidden the cursor and it works great until the cursor moves out of the window (if windowed) or the cursor moves to the edge of the window in fullscreen view. Obviously this is because the control is no longer receiving MouseMove messages, it seems that the best way round this would be to move the mouse back to the center of the screen after every update but I'm not sure how to go about this. Any Ideas? Here's my current Mouse class...
using System.Windows.Forms;
using System.Drawing;

namespace Engine.Input
{
    public class Mouse
    {
        private Point m_currentLocation;
        private Point m_previousLocation;

        private int m_deltaX = 0;
        private int m_deltaY = 0;

        public Mouse(Control control)
        {
            control.MouseMove += new MouseEventHandler(MouseMove);
            Cursor.Hide();
        }

        private void MouseMove(object sender, MouseEventArgs e)
        {
            m_currentLocation = e.Location;
        }

        public void Update()
        {
            m_deltaX = m_currentLocation.X - m_previousLocation.X;
            m_deltaY = m_currentLocation.Y - m_previousLocation.Y;

            m_previousLocation = m_currentLocation;
        }

        public int DeltaX
        {
            get { return m_deltaX; }
        }

        public int DeltaY
        {
            get { return m_deltaY; }
        }
    }
}

Thanks in advance for any help!

Share this post


Link to post
Share on other sites
Advertisement
How about something like this?


public void Update()
{
m_deltaX = m_currentLocation.X - m_previousLocation.X;
m_deltaY = m_currentLocation.Y - m_previousLocation.Y;

System.Windows.Forms.Cursor.Position = new Point(m_control.Left + m_control.Width / 2, m_control.Top + m_control.Height / 2);

m_previousLocation = System.Windows.Forms.Cursor.Position;
}

Share this post


Link to post
Share on other sites
Excellent! That works great!

I never realised you could get the cursor at any point that way. It means I dont have to listen for Mouse Move events now. Is there anyway you can get the current state of the buttons or wheel without events as well?

Thanks a lot for your help! rate++

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!