Example #1
0
 public Mouse(DirectInput DirectInput)
 {
     _Mouse = new SharpDX.DirectInput.Mouse(DirectInput);
     _Mouse.Acquire();
     UpdateMouseState();
     UpdateMouseState();
 }
Example #2
0
 public SpriteWindow()
 {
     Keyboard = new DirectInput.Keyboard(DirectInput);
     Keyboard.Acquire();
     Mouse = new DirectInput.Mouse(DirectInput);
     Mouse.Acquire();
 }
Example #3
0
        public Game()
        {
            renderForm            = new RenderForm("D3D11 Planets");
            renderForm.MouseMove += (object sender, System.Windows.Forms.MouseEventArgs e) => {
                realMousePos = new Vector2(e.Location.X, e.Location.Y);
            };
            renderForm.WindowState        = System.Windows.Forms.FormWindowState.Maximized;
            renderForm.AllowUserResizing  = true;
            renderForm.ClientSizeChanged += (object sender, EventArgs e) => {
                resizePending = true;
            };

            DInput.DirectInput directInput = new DInput.DirectInput();
            keyboard = new DInput.Keyboard(directInput);
            mouse    = new DInput.Mouse(directInput);

            keyboard.Acquire();
            mouse.Acquire();

            renderer = new Renderer(this, renderForm);

            Shaders.Load(renderer.Device, renderer.Context);
            Resources.Load(renderer.Device);

            Initialize();
        }
Example #4
0
 public SharpDXMouse(CursorPositionTranslater positionTranslater)
 {
     this.positionTranslater = positionTranslater;
     mouseCounter = new MouseDeviceCounter();
     directInput = new DInput.DirectInput();
     mouse = new DInput.Mouse(directInput);
     mouse.Properties.AxisMode = DInput.DeviceAxisMode.Absolute;
     mouse.Acquire();
     currentState = new DInput.MouseState();
 }
Example #5
0
 public SharpDXMouse(Window window)
 {
     positionTranslater = new CursorPositionTranslater(window);
     mouseCounter       = new MouseDeviceCounter();
     directInput        = new DInput.DirectInput();
     mouse = new DInput.Mouse(directInput);
     mouse.Properties.AxisMode = DInput.DeviceAxisMode.Absolute;
     mouse.Acquire();
     currentState = new DInput.MouseState();
 }
Example #6
0
        public InputDeviceMouse(DirectInput di, DeviceInstance d)
        {
            // those silly foreign people call mouse something other than it in english, so we need to fix it to english

            msi = new InputDeviceIdentity()
            {
                Instanceguid = d.InstanceGuid, Productguid = d.ProductGuid, Name = "Mouse"
            };

            mouse = new SharpDX.DirectInput.Mouse(di);
            mouse.SetNotification(eventhandle);
            mouse.Acquire();
            Capabilities c = mouse.Capabilities;

            butstate = new bool[c.ButtonCount];
        }
Example #7
0
        /// <summary>
        /// Collect the current data from the device
        /// </summary>
        public override void GetData( )
        {
            // Make sure there is a valid device.
            if (null == m_device)
            {
                return;
            }

            // Poll the device for info.
            try {
                m_device.Poll( );
            }
            catch (SharpDXException e) {
                if ((e.ResultCode == ResultCode.NotAcquired) || (e.ResultCode == ResultCode.InputLost))
                {
                    // Check to see if either the app needs to acquire the device, or
                    // if the app lost the device to another process.
                    try {
                        // Acquire the device - if the (main)window is active
                        if (Activated)
                        {
                            m_device.Acquire( );
                        }
                    }
                    catch (SharpDXException) {
                        // Failed to acquire the device. This could be because the app doesn't have focus.
                        return; // EXIT unaquired
                    }
                }
                else
                {
                    log.Error("Unexpected Poll Exception", e);
                    return; // EXIT see ex code
                }
            }


            // Get the state of the device - retaining the previous state to find the lates change
            m_prevState = m_state;
            try { m_state = m_device.GetCurrentState( ); }
            // Catch any exceptions. None will be handled here,
            // any device re-aquisition will be handled above.
            catch (SharpDXException) {
                return;
            }
        }
        //*******************************************************//
        //                      METHODS                          //
        //*******************************************************//
        public static void Initialize()
        {
            if (IsInitialized) return;
            
            _DirectInput = new DirectInput();
            _Mouse = new SharpDX.DirectInput.Mouse(_DirectInput);
            _Mouse.Properties.AxisMode = DeviceAxisMode.Relative;
            try
            {
                _Mouse.Acquire();
            }
            catch (SharpDX.SharpDXException)
            {
                Console.WriteLine("Error: Failed to aquire mouse !");
                return;
            }

            IsInitialized = true;
        }
Example #9
0
        public override Action Start()
        {
            IntPtr handle = Process.GetCurrentProcess().MainWindowHandle;

            mouseDevice = new SharpDX.DirectInput.Mouse(directInputInstance);
            if (mouseDevice == null)
            {
                throw new Exception("Failed to create mouse device");
            }

            mouseDevice.SetCooperativeLevel(handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive);
            mouseDevice.Properties.AxisMode = DeviceAxisMode.Relative;   // Get delta values
            mouseDevice.Acquire();

            getPressedStrategy = new GetPressedStrategy <int>(IsDown);
            setPressedStrategy = new SetPressedStrategy <int>(SetButtonDown, SetButtonUp);

            OnStarted(this, new EventArgs());
            return(null);
        }