Ejemplo n.º 1
0
        /// <summary>
        /// A check to see if a mouse button has been held down.
        /// </summary>
        /// <param name="button">The button to be checked.</param>
        /// <returns>The result of the check.</returns>
        public bool IsHeld(MouseButtons button)
        {
            byte[] curr = current.GetMouseButtons();
            byte[] prev = previous.GetMouseButtons();

            return(curr[(int)button] == 0 && prev[(int)button] == 0);
        }
Ejemplo n.º 2
0
        public void AcceptMouseInput(Input input, InputState inputState)
        {
            MouseState mouseState = input.GetMouseState();

            if (mouseState.GetMouseButtons()[0] > 0) // left click
            {
                inputState.AnalogButtons[(int)AnalogButtons.RightTrigger] = 0xFF;
            }
            if (mouseState.GetMouseButtons()[1] > 0) // right click
            {
                inputState.AnalogButtons[(int)AnalogButtons.LeftTrigger] = 0xFF;
            }
            if (mouseState.GetMouseButtons()[2] > 0) // middle click
            {
                inputState.Buttons |= Buttons.RightThumb;
            }

            Point center = new Point(Location.X + Size.Width / 2, Location.Y + Size.Height / 2);

            inputState.ThumbRX += (short)((MousePosition.X - center.X) * 1000);
            inputState.ThumbRY += (short)(-(MousePosition.Y - center.Y) * 1000);

            Cursor.Position = center;

            previousMousePosition = Cursor.Position;
        }
        /// <summary>
        ///		Returns true if the given mouse key has just been pressed.
        /// </summary>
        /// <param name="key">Mouse key code of key to check.</param>
        /// <returns>True if mouse key has just been pressed.</returns>
        private bool MousePressed(KeyCodes key)
        {
            byte[] mouseButtons         = _mouseState.GetMouseButtons();
            byte[] previousMouseButtons = _previousMouseState.GetMouseButtons();
            if (mouseButtons == null || previousMouseButtons == null)
            {
                return(false);
            }

            byte prevState = previousMouseButtons[((int)key) - 160];

            return((mouseButtons[((int)key) - 160] != 0) && prevState == 0);
        }
Ejemplo n.º 4
0
        private void UpdateMouse()
        {
            MouseState ms = mouse.CurrentMouseState;

            byte[] buttons = ms.GetMouseButtons();

            // update all the buttons
            for (int i = 0; i < buttons.Length; ++i)
            {
                // change all "Released" to "Up" and
                // all "Pressed" to "Down"
                if (mouseButtonState[i] == State.Released)
                {
                    mouseButtonState[i] = State.Up;
                }
                if (mouseButtonState[i] == State.Pressed)
                {
                    mouseButtonState[i] = State.Down;
                }

                mouseButtonState[i] = ComputeNewState(mouseButtonState[i], buttons[i] > 0);
            }

            // update mouse position and deltas
            mp.dX = ms.X - mp.X;                        // [delta] = [new position] - [old position]
            mp.X  = ms.X;
            mp.dY = ms.Y - mp.Y;
            mp.Y  = ms.Y;

            // DirectInput.MouseState.Z is a delta, where
            // 120 is the movement for one individual scroll
            mp.dZ = ms.Z / 120;
        }
Ejemplo n.º 5
0
            internal void Update(MouseState state)
            {
                m_x += state.X;
                m_y += state.Y;

                m_b = 0;
                byte[] buttonState = state.GetMouseButtons();
                if ((buttonState[0] & 0x80) != 0)
                {
                    m_b |= 1;
                }
                if ((buttonState[1] & 0x80) != 0)
                {
                    m_b |= 2;
                }
                if ((buttonState[2] & 0x80) != 0)
                {
                    m_b |= 4;
                }
                if ((buttonState[3] & 0x80) != 0)
                {
                    m_b |= 8;
                }
                if ((buttonState[4] & 0x80) != 0)
                {
                    m_b |= 16;
                }
                if ((buttonState[5] & 0x80) != 0)
                {
                    m_b |= 32;
                }
            }
Ejemplo n.º 6
0
    public void UpdateInput()
    {
        MouseState state = device.CurrentMouseState;

        values.Yaw   = state.X;
        values.Pitch = state.Y;

        byte [] buttonStatus = state.GetMouseButtons();
        if (buttonStatus[0] != 0)
        {
            values.FireButtonPushed = true;
        }
        else
        {
            values.FireButtonPushed = false;
        }

        if (buttonStatus[1] != 0)
        {
            values.ThrustButtonPushed = true;
        }
        else
        {
            values.ThrustButtonPushed = false;
        }
    }
Ejemplo n.º 7
0
        public void UpdateMouse()
        {
            string info = "Mouse: ";

            //Get Mouse State.
            MouseState state = mouse.CurrentMouseState;


            //Capture Position.
            info += "X:" + state.X + " ";
            info += "Y:" + state.Y + " ";
            info += "Z:" + state.Z + " ";

            //Capture Buttons.
            byte[] buttons = state.GetMouseButtons();
            for (int i = 0; i < buttons.Length; i++)
            {
                if (buttons[i] != 0)
                {
                    info += "Button:" + i + " ";
                }
            }

            label1.Text = info;
        }
Ejemplo n.º 8
0
        public void Poll()
        {
            LockMouse = false;
            try
            {
                CurrentMouseState = Device.CurrentMouseState;
                ButtonState       = CurrentMouseState.GetMouseButtons();

                for (int i = 0; i < ButtonState.Length; i++)
                {
                    if (ButtonsHeld[i])
                    {
                        ButtonsPressed[i] = false;
                    }
                    else
                    {
                        ButtonsPressed[i] = (ButtonState[i] & 128) > 0;
                    }

                    ButtonsHeld[i] = (ButtonState[i] & 128) > 0;
                }
            }
            catch (NotAcquiredException)
            {
                try { _Device.Acquire(); }
                catch (Exception) { }
            }
            catch (InputException) { }
            catch (NullReferenceException) { }
        }
Ejemplo n.º 9
0
        public bool ButtonDown(MouseButtons button)
        {
#if XBOX360
            return(false);
#else
            if (mActive == false)
            {
                return(false);
            }

#if FRB_MDX
            byte[] tempMouseButton = mMouseState.GetMouseButtons();
            if (tempMouseButton != null && tempMouseButton.Length != 0)
            {
                return(mMouseState.GetMouseButtons()[(int)button] != 0);
            }
            else
            {
                return(false);
            }
#else
            switch (button)
            {
            case MouseButtons.LeftButton:
                return(!InputManager.CurrentFrameInputSuspended && mMouseState.LeftButton == ButtonState.Pressed);

            case MouseButtons.RightButton:
                return(!InputManager.CurrentFrameInputSuspended && mMouseState.RightButton == ButtonState.Pressed);

#if !SILVERLIGHT
            case MouseButtons.MiddleButton:
                return(!InputManager.CurrentFrameInputSuspended && mMouseState.MiddleButton == ButtonState.Pressed);

            case MouseButtons.XButton1:
                return(!InputManager.CurrentFrameInputSuspended && mMouseState.XButton1 == ButtonState.Pressed);

            case MouseButtons.XButton2:
                return(!InputManager.CurrentFrameInputSuspended && mMouseState.XButton2 == ButtonState.Pressed);
#endif
            default:
                return(false);
            }
#endif
#endif
        }
Ejemplo n.º 10
0
Archivo: UI.cs Proyecto: KeiPG/rubixs
        private void ReadMouse()
        {
            MouseState state = mouse.CurrentMouseState;

            mousepos.X = state.X;
            mousepos.Y = state.Y;
            mousepos.Z = state.Z;

            byte[] buttons = state.GetMouseButtons();
            if (buttons[1] != 0) //right button
            {
                float mx = mouse.CurrentMouseState.X;
                float my = mouse.CurrentMouseState.Y;
                //for the pen input, it goes insainly fast
                if (Math.Abs(mousepos.X) > 10)
                {
                    //mousepos.X = mousepos.X%10;
                }
                if (Math.Abs(mousepos.Y) > 10)
                {
                    //mousepos.Y = mousepos.Y%10;
                }
                theta += Geometry.DegreeToRadian(mousepos.X);
                phi   += Geometry.DegreeToRadian(mousepos.Y);
            }
            if (mousepos.Z > 0) //scroll wheel
            {
                if (keyboard.GetCurrentKeyboardState()[Key.LeftControl])
                {
                    spacing -= .1f;
                }
                else
                {
                    rho -= 1;
                }
            }
            else if (mousepos.Z < 0)
            {
                if (keyboard.GetCurrentKeyboardState()[Key.LeftControl])
                {
                    spacing += .1f;
                }
                else
                {
                    rho += 1;
                }
            }
            if (buttons[2] != 0) //middle button
            {
                if (!middle)
                {
                    rubixCube.Scramble();
                }
            }
            middle = buttons[2] == 0;
            //mouse.
        }
Ejemplo n.º 11
0
        /// <summary>
        /// this function gives values to the mouse position for use later.
        /// this also makes sure the user cant break the code by making the mouse
        /// go places i dont want them to.
        /// this also does the zooming functions on the scroll wheel and when pressed down will scramble.
        /// </summary>
        private void ReadMouse()
        {
            MouseState state = mouse.CurrentMouseState;

            mousepos.X = state.X;
            mousepos.Y = state.Y;
            mousepos.Z = state.Z;


            byte[] buttons = state.GetMouseButtons();
            if (buttons[1] != 0) //right button
            {
                float mx = mouse.CurrentMouseState.X;
                float my = mouse.CurrentMouseState.Y;
                //for the pen input, it goes insainly fast
                if (Math.Abs(mousepos.X) > 10)
                {
                    mousepos.X = mousepos.X % 10;
                }
                if (Math.Abs(mousepos.Y) > 10)
                {
                    mousepos.Y = mousepos.Y % 10;
                }
                theta += Geometry.DegreeToRadian(mousepos.X);
                phi   += Geometry.DegreeToRadian(mousepos.Y);
            }
            float Dif = mousepos.Z - OldZ;

            OldZ = mousepos.Z;
            if (Dif != 0) //scroll wheel
            {
                if (keyboard.GetCurrentKeyboardState()[Key.LeftControl])
                {
                    spacing -= 0.0005f * Dif;
                    Console.WriteLine("rho = " + rho + " phi = " + phi + " theta = " + theta + " spacing = " + spacing);
                }
                else
                {
                    rho += 0.005 * Dif;
                }
            }


            if (buttons[2] != 0) //middle button
            {
                if (!middle)
                {
                    rubixCube.Scramble();
                }
            }
            middle = buttons[2] == 0;
            //mouse.
        }
Ejemplo n.º 12
0
        public void Update()
        {
            m_KeyState   = m_keyboard.GetCurrentKeyboardState();
            m_MouseState = m_mouse.CurrentMouseState;

            //get state of mouse buttons
            byte[] buttons = m_MouseState.GetMouseButtons();
            m_bLeftMouseBtn   = (buttons[0] == 128);
            m_bRightMouseBtn  = (buttons[1] == 128);
            m_bMiddleMouseBtn = (buttons[2] == 128);
            //Trace.WriteLine("left button = " + m_bLeftMouseBtn.ToString());
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Обновить состояние мыши
        /// </summary>
        public static void Update()
        {
            MouseState ms = devMouse.CurrentMouseState;                     // текущее состояние мыши

            Coords = new Vector3(ms.X, ms.Y, ms.Z) * Sensitive;             // установить значение координат мыши

            byte[] btns = ms.GetMouseButtons();                             // получить состояние кнопок мыши

            // Установить признак нажатия кнопок:
            Buttons.Left   = (btns[0] != 0);                                    // левой
            Buttons.Right  = (btns[1] != 0);                                    // правой
            Buttons.Middle = (btns[2] != 0);                                    // средней
        }
Ejemplo n.º 14
0
        public void Update()
        {
            if (Prometheus.Instance.MdxInputAquired)
            {
                keyState   = MdxInput.Keyboard.GetCurrentKeyboardState();
                mouseState = MdxInput.Mouse.CurrentMouseState;

                //get state of mouse buttons
                byte[] buttons = mouseState.GetMouseButtons();
                bLeftMouseBtn    = (buttons[0] == 128);
                m_bRightMouseBtn = (buttons[1] == 128);
                bMiddleMouseBtn  = (buttons[2] == 128);
                //Trace.WriteLine("left button = " + m_bLeftMouseBtn.ToString());
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Updates the state of the which buttons are pressed.
        /// </summary>
        protected void UpdatePressedButtons()
        {
            byte[] buttons = _state.GetMouseButtons();

            for (int i = 0; i < buttons.Length; i++)
            {
                if (buttons[i] != 0)
                {
                    _buttons[i] = true;
                }
                else
                {
                    _buttons[i] = false;
                }
            }
        }
Ejemplo n.º 16
0
        public void UpdateUI()
        {
            MouseState mouseStateData = new MouseState();

            // Get the current state of the mouse device.
            mouseStateData = applicationDevice.CurrentMouseState;
            byte[] buttons = mouseStateData.GetMouseButtons();

            // Display some info about the device.
            if (0 != buttons[0])
            {
                lblButton0.Text = "Down";
            }
            else
            {
                lblButton0.Text = "Up";
            }
            if (0 != buttons[1])
            {
                lblButton1.Text = "Down";
            }
            else
            {
                lblButton1.Text = "Up";
            }
            if (0 != buttons[2])
            {
                lblButton2.Text = "Down";
            }
            else
            {
                lblButton2.Text = "Up";
            }
            if (0 != (mouseStateData.X | mouseStateData.Y | mouseStateData.Z))
            {
                lbStatus.Items.Add(mouseStateData.X + ", " + mouseStateData.Y + ", " + mouseStateData.Z);
                if (lbStatus.Items.Count > 10)
                {
                    lbStatus.Items.RemoveAt(1);
                }
                lbStatus.SelectedIndex = lbStatus.Items.Count - 1;
            }
        }
Ejemplo n.º 17
0
        internal void updateMouse()
        {
            MouseState mouseState = mouseDevice.CurrentMouseState;

            //Hacer copia del estado actual
            Array.Copy(currentMouseButtonsState, previousMouseButtonsState, currentMouseButtonsState.Length);

            //Actualizar estado de cada boton
            byte[] mouseStateButtons = mouseState.GetMouseButtons();
            currentMouseButtonsState[(int)MouseButtons.BUTTON_LEFT]   = mouseStateButtons[(int)MouseButtons.BUTTON_LEFT] != 0;
            currentMouseButtonsState[(int)MouseButtons.BUTTON_MIDDLE] = mouseStateButtons[(int)MouseButtons.BUTTON_MIDDLE] != 0;
            currentMouseButtonsState[(int)MouseButtons.BUTTON_RIGHT]  = mouseStateButtons[(int)MouseButtons.BUTTON_RIGHT] != 0;


            //Mouse X, Y relative
            if (enableMouseFiltering)
            {
                performMouseFiltering(mouseState.X, mouseState.Y);
                performMouseSmoothing(deltaMouseX, deltaMouseY);
            }
            else
            {
                deltaMouseX = mouseState.X;
                deltaMouseY = mouseState.Y;
            }


            //Mouse Wheel
            if (mouseState.Z > 0)
            {
                deltaMouseWheel = 1.0f;
            }
            else if (mouseState.Z < 0)
            {
                deltaMouseWheel = -1.0f;
            }
            else
            {
                deltaMouseWheel = 0.0f;
            }
        }
Ejemplo n.º 18
0
        private void UpdateInputState()
        {
            // Check the mouse state
            MouseState state = mouse.CurrentMouseState;

            // Buttons
            byte[] buttons = state.GetMouseButtons();

            if (buttons[1] != 0)
            {
                worldMatrix = Matrix.RotationYawPitchRoll((x - state.X) * 0.01f, 0, 0) * worldMatrix;
                worldMatrix = Matrix.RotationYawPitchRoll(0, (y - state.Y) * 0.01f, 0) * worldMatrix;
            }
            else if (buttons[2] != 0)
            {
                worldMatrix = worldMatrix * Matrix.Translation(0, 0, (z - state.Z) * 0.005f);
            }
            else
            {
                x = state.X;
                y = state.Y;
                z = state.Z;
            }
        }
Ejemplo n.º 19
0
        void XCE_Shown(object sender, System.EventArgs e)
        {
            try
            {
                this.WindowState = FormWindowState.Normal;
                System.Threading.Thread.Sleep(1000);

                Prompt.Show();
                while (!Prompt.IsDisposed)                  // waits for it to be disposed
                {
                    System.Threading.Thread.Sleep(1);
                    Application.DoEvents();
                }
                Input = new Input(this);
                Xbox.Connect(Prompt.DebugName);
                Xbox.Gamepad.InitializeControllerHook();
                Xbox.Gamepad.OverrideControllers(true);

                while (running)
                {
                    NewInput = new InputState();
                    //DateTime before = DateTime.Now;

                    ParseKeyboardInput(ref NewInput);

                    #region Mouse Input
                    MouseState Mouse = Input.GetMouseState();
                    if (Mouse.GetMouseButtons()[0] > 0)                     // left click
                    {
                        NewInput.AnalogButtons[(int)AnalogButtons.RightTrigger] = 0xFF;
                    }
                    if (Mouse.GetMouseButtons()[1] > 0)                     // right click
                    {
                        NewInput.AnalogButtons[(int)AnalogButtons.LeftTrigger] = 0xFF;
                    }
                    if (Mouse.GetMouseButtons()[2] > 0)                     // middle click
                    {
                        NewInput.Buttons |= Buttons.RightThumb;
                    }

                    /*
                     * // get mouse input with separate function...we need to capture constantly instead of 30fps
                     *
                     * NewInput.ThumbRX = (short)(Mouse.X * 0x7FF);
                     * NewInput.ThumbRY = (short)(-Mouse.Y * 0x7FF);
                     *
                     *
                     * //NewInput.ThumbRX = (short)(((float)short.MaxValue * (Mouse.X / 2)) / 4);
                     * //NewInput.ThumbRY = (short)(-((float)short.MaxValue * (Mouse.Y / 2) / 4));
                     */
                    #endregion


                    //int PollsPerSecond = 30;
                    //System.Threading.Thread.Sleep(1000 / PollsPerSecond);
                    System.Threading.Thread.Sleep(1);
                    Xbox.Gamepad.SetState(0, NewInput);
                    Application.DoEvents();
                }
            }
            catch
            {
                Hide();
                MessageBox.Show("You slipped one past the goalie, don't let it happen again ;P", "Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Close();
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// A check to see which mouse button has been pressed.
        /// </summary>
        /// <param name="button">The button to be checked.</param>
        /// <returns>The result of the check.</returns>
        public bool IsPressed(MouseButtons button)
        {
            byte[] pressed = current.GetMouseButtons();

            return(pressed[(int)button] == 0);
        }
Ejemplo n.º 21
0
        private void FrameMoveMouse()
        {
            _mouseState = _mouse.CurrentMouseState;

            byte[] buttons = _mouseState.GetMouseButtons();
        }
Ejemplo n.º 22
0
        // poll method
        public void Poll()
        {
            KeyboardState oldkeydata = null;

            // Bool flag that is set when it's ok
            // to get device state information.
            bool bKeyboardOk = false;
            bool bMouseOk    = false;
            bool bJoystickOk = false;


            MouseState    oldmousedata    = new MouseState();
            JoystickState oldjoystickdata = new JoystickState();

            oldkeydata = m_keydata;

            // get keyboard data
            try
            {
                KeyboardDev.Poll();
                bKeyboardOk = true;
            }
            catch (InputException ex)
            {
                // Check to see if either the app
                // needs to acquire the device, or
                // if the app lost the device to another
                // process.
                if ((ex is NotAcquiredException))
                {
                    try
                    {
                        // Reacquire the device.
                        KeyboardDev.Acquire();
                        // Set the flag for now.
                        bKeyboardOk = true;
                    }
                    catch (InputException ex2)
                    {
                        if (ex2 is OtherApplicationHasPriorityException)
                        {       // Something very odd happened.
                            //Console.AddLine("An unknown error has occcurred. This app won't be able to process device info.");
                        }
                        // Failed to aquire the device.
                        // This could be because the app
                        // doesn't have focus.
                        bKeyboardOk = false;
                    }
                }
                else
                {
                    KeyboardDev = new Device(SystemGuid.Keyboard);
                    KeyboardDev.SetCooperativeLevel(m_form, CooperativeLevelFlags.NoWindowsKey | CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Foreground);
                    KeyboardDev.SetDataFormat(DeviceDataFormat.Keyboard);
                }
            }

            // get mouse data
            try
            {
                MouseDev.Poll();
                bMouseOk = true;
            }
            catch (InputException ex)
            {
                // Check to see if either the app
                // needs to acquire the device, or
                // if the app lost the device to another
                // process.
                if ((ex is NotAcquiredException))
                {
                    try
                    {
                        // Reacquire the device.
                        MouseDev.Acquire();
                        // Set the flag for now.
                        bMouseOk = true;
                        //						Console.AddLine("had to reacquire the mouse");
                    }
                    catch (InputException ex2)
                    {
                        if (ex2 is OtherApplicationHasPriorityException)
                        {       // Something very odd happened.
                            System.Diagnostics.Debug.WriteLine("An unknown error has occcurred. This app won't be able to process device info. " + ex2.ErrorString);
                        }
                        // Failed to aquire the device.
                        // This could be because the app
                        // doesn't have focus.
                        bMouseOk = false;
                    }
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine(ex.ErrorString);
                    MouseDev.Dispose();
                    MouseDev = new Device(SystemGuid.Mouse);
                    MouseDev.SetCooperativeLevel(m_form, CooperativeLevelFlags.Exclusive | CooperativeLevelFlags.Foreground);
                    MouseDev.SetDataFormat(DeviceDataFormat.Mouse);
                }
            }

            // get joystick data
            try
            {
                if (m_bJoystickSet)
                {
                    JoystickDev.Poll();
                    bJoystickOk = true;
                }
            }
            catch (InputException ex)
            {
                // Check to see if either the app
                // needs to acquire the device, or
                // if the app lost the device to another
                // process.
                if ((ex is NotAcquiredException))
                {
                    try
                    {
                        if (JoystickDev != null)
                        {
                            // Create the device.
                            // Set the cooperative level for the device.
                            JoystickDev.SetCooperativeLevel(m_form, CooperativeLevelFlags.Exclusive | CooperativeLevelFlags.Foreground);
                            // Set the data format to the Joystick pre-defined format.
                            JoystickDev.SetDataFormat(DeviceDataFormat.Joystick);

                            // Now find out how many POV's the device has
                            // for displaying info in the UI thread.
                            m_NumPov       = JoystickDev.Caps.NumberPointOfViews;
                            m_bJoystickSet = true;
                        }
                        // Reacquire the device.
                        JoystickDev.Acquire();
                        // Set the flag for now.
                        bJoystickOk = true;
                    }
                    catch (InputException ex2)
                    {
                        if (ex2 is OtherApplicationHasPriorityException)
                        {       // Something very odd happened.
                            //Console.AddLine("An unknown error has occcurred. This app won't be able to process device info.");
                        }
                        // Failed to aquire the device.
                        // This could be because the app
                        // doesn't have focus.
                        bJoystickOk = false;
                    }
                }
                else
                {
                    if (JoystickDev != null)
                    {
                        // Create the device.
                        // Set the cooperative level for the device.
                        JoystickDev.SetCooperativeLevel(m_form, CooperativeLevelFlags.Exclusive | CooperativeLevelFlags.Foreground);
                        // Set the data format to the Joystick pre-defined format.
                        JoystickDev.SetDataFormat(DeviceDataFormat.Joystick);

                        // Now find out how many POV's the device has
                        // for displaying info in the UI thread.
                        m_NumPov       = JoystickDev.Caps.NumberPointOfViews;
                        m_bJoystickSet = true;
                        // Reacquire the device.
                        try
                        {
                            JoystickDev.Acquire();
                        }
                        catch { }

                        // Set the flag for now.
                        bJoystickOk = true;
                    }
                }
            }
            if (bJoystickOk == true)
            {
                // Get the state of the device
                try { m_joystick = JoystickDev.CurrentJoystickState; }
                // Catch any exceptions. None will be handled here,
                // any device re-aquisition will be handled above.
                catch (DirectXException) { }
            }

            try
            {
                if (bKeyboardOk)
                {
                    m_keydata = KeyboardDev.GetCurrentKeyboardState();
                }
                if (bMouseOk)
                {
                    m_mousedata = MouseDev.CurrentMouseState;
                    m_MouseX   += m_mousedata.X;
                    m_MouseY   += m_mousedata.Y;
                    m_MouseZ   += m_mousedata.Z;

                    m_MousePoint.X += m_mousedata.X;
                    m_MousePoint.Y += m_mousedata.Y;
                }

                // call any axis actions
                foreach (AxisMapping map in m_AxisActionMap)
                {
                    switch (map.key)
                    {
                    case 0:
                        map.action(m_mousedata.X);
                        break;

                    case 1:
                        map.action(m_mousedata.Y);
                        break;

                    case 2:
                        map.action(m_mousedata.Z);
                        break;

                    case 3:
                        map.action(m_joystick.X);
                        break;

                    case 4:
                        map.action(m_joystick.Y);
                        break;

                    case 5:
                        map.action(m_joystick.Z);
                        break;
                    }
                }

                // only process the action map if the console is not visible
                if (!Console.IsVisible)
                {
                    foreach (Mapping map in m_ActionMap)
                    {
                        // if this is against the keyboard
                        if (map.key < 256)
                        {
                            if (m_keydata[(Key)map.key])
                            {
                                if (!map.bOnTransition || oldkeydata[(Key)map.key])
                                {
                                    map.action();
                                }
                            }
                        }
                        else if (map.key < 264)  // space for 8 mouse buttons
                        {
                            if ((m_mousedata.GetMouseButtons()[map.key - 256] & 0x80) != 0)
                            {
                                if (!map.bOnTransition || (oldmousedata.GetMouseButtons()[map.key - 256] & 0x80) == 0)
                                {
                                    map.action();
                                }
                            }
                        }
                        else  // joystick buttons
                        {
                            if ((m_joystick.GetButtons()[map.key - 264] & 0x80) != 0)
                            {
                                if (!map.bOnTransition || (oldjoystickdata.GetButtons()[map.key - 264] & 0x80) == 0)
                                {
                                    map.action();
                                }
                            }
                        }
                    }
                }
            }
            catch { }
        }
Ejemplo n.º 23
0
 public bool MouseButtonDown(MouseButton button)
 {
     return((mouseState.GetMouseButtons() [( int )button] & 0x80) != 0);
 }
Ejemplo n.º 24
0
        public void Update()
        {
            do
            {
                // Try to get the current state
                try
                {
                    state = mouse.CurrentMouseState;

                    // if fetching the state is successful -> exit loop
                    break;
                }
                catch (InputException)
                {
                    // let the application handle Windows messages
                    Application.DoEvents();

                    // Try to get reacquire the keyboard
                    // and don't care about exceptions
                    try
                    {
                        mouse.Acquire();
                    }
                    catch (InputLostException)
                    {
                        continue;
                    }
                    catch(OtherApplicationHasPriorityException)
                    {
                        continue;
                    }
                }
            }
            while(true); // Do this until it's successful

            if(m_bWindowed)
            {
                m_XPos = Cursor.Position.X -  m_Owner.Left;
                m_YPos = Cursor.Position.Y - (m_Owner.Top + 23);
            }
            else
            {
                m_XPos += XDelta;
                m_YPos += YDelta;
            }

            byte[] btns = state.GetMouseButtons();
            for(int i = 0; i < btns.Length; i++)
            {
                if(btns[i] != 0)
                {
                    buttons[i] = true;
                }
                else
                {
                    buttons[i] = false;
                }
            }

            m_ObjectSpace = Vector3.Unproject(
                new Vector3(m_XPos, m_YPos, 0f),
                d3ddevice.Viewport, d3ddevice.Transform.Projection,
                d3ddevice.Transform.View, d3ddevice.Transform.World);

            m_ObjectSpace2 = Vector3.Unproject(
                new Vector3(m_XPos, m_YPos, 1f),
                d3ddevice.Viewport, d3ddevice.Transform.Projection,
                d3ddevice.Transform.View, d3ddevice.Transform.World);
        }
Ejemplo n.º 25
0
        // hot keys defined
        private void ReadKeyboard()
        {
            try
            {
                keyb.Acquire();
                KeyboardState keys = keyb.GetCurrentKeyboardState();

                if (keys[Key.RightArrow] || keys[Key.A])
                {
                    //LeftRightOffset += 1000;
                    LeftRightOffset += (zoom) / 40f;
                }
                if (keys[Key.LeftArrow] || keys[Key.D])
                {
                    // LeftRightOffset -= 1000;
                    LeftRightOffset -= (zoom) / 40f;
                }

                if (keys[Key.UpArrow] || keys[Key.W])
                {
                    UpDownOffset -= (zoom) / 40f;
                }
                if (keys[Key.DownArrow] || keys[Key.S])
                {
                    UpDownOffset += (zoom) / 40f;
                } // reset
                if (keys[Key.NumPad1])
                {
                    //UpDownOffset = 400;
                    //LeftRightOffset = 800;
                    //zoom = -1000;

                    UpDownOffset    = cUpDownOffset;
                    LeftRightOffset = cLeftRightOffset;
                    zoom            = czoom;



                    //runTimeMs += 1;
                }
                if (keys[Key.NumPad2])
                {
                    LeftRightOffset = 12644;
                    UpDownOffset    = 10159;
                    zoom            = -25313;
                }
                if (keys[Key.NumPad3])
                {
                    LeftRightOffset = 120994;
                    UpDownOffset    = 10125;
                    zoom            = -27287;
                }

                if (keys[Key.NumPad9])
                {
                    SorterRun = 1;

                    // turn on stat loger for links per sec
                    LinkRate_Stop        = 0;
                    LinkRate_CountPerSec = 0;
                }
                if (keys[Key.NumPad8])
                {
                    SorterRun = 0;
                }
            }
            catch
            {
            }

            //MouseState CurrentMouseState
            double d;

            try
            {
                mkeyb.Acquire();
                MouseState mKeys = mkeyb.CurrentMouseState;
                byte[]     b     = mKeys.GetMouseButtons();


                if (mKeys.Z > 0)
                {
                    //zoom += 5000;
                    d     = zoom;
                    zoom -= (int)zoom * 0.05f;
                }
                if (mKeys.Z < 0)
                {
                    //zoom -= 5000;
                    zoom += (int)zoom * 0.05f;
                }

                if (b[0] == 128) // left click
                {
                    //UpDownOffset = cUpDownOffset;
                    //LeftRightOffset = cLeftRightOffset;
                    //zoom = czoom;
                }

                //mouse_x = mKeys.x;
            }
            catch
            {
            }
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Updates the mouse device.
 /// </summary>
 public void Update()
 {
     _state   = _device.CurrentMouseState;
     _buttons = new bool[_state.GetMouseButtons().Length];
     UpdatePressedButtons();
 }
Ejemplo n.º 27
0
        public void Poll()
        {
            LockMouse = false;
            try
            {
                CurrentMouseState = Device.CurrentMouseState;
                ButtonState = CurrentMouseState.GetMouseButtons();

                for (int i = 0; i < ButtonState.Length; i++)
                {
                    if (ButtonsHeld[i])
                        ButtonsPressed[i] = false;
                    else
                        ButtonsPressed[i] = (ButtonState[i] & 128) > 0;

                    ButtonsHeld[i] = (ButtonState[i] & 128) > 0;
                }
            }
            catch (NotAcquiredException)
            {
                try { _Device.Acquire(); }
                catch (Exception) { }
            }
            catch (InputException) { }
            catch (NullReferenceException) { }
        }
Ejemplo n.º 28
0
            internal void Update(MouseState state)
            {
                m_x += state.X;
                m_y += state.Y;

                m_b = 0;
                byte[] buttonState = state.GetMouseButtons();
                if ((buttonState[0] & 0x80) != 0) m_b |= 1;
                if ((buttonState[1] & 0x80) != 0) m_b |= 2;
                if ((buttonState[2] & 0x80) != 0) m_b |= 4;
                if ((buttonState[3] & 0x80) != 0) m_b |= 8;
                if ((buttonState[4] & 0x80) != 0) m_b |= 16;
                if ((buttonState[5] & 0x80) != 0) m_b |= 32;
            }
        /// <summary>
        ///		Takes a snapshot of the mouse state for immediate input checking.
        /// </summary>
        private void CaptureImmediateMouse()
        {
            // throw away the collection of buffered data
            if (useMouseEvents)
                mouseDevice.GetBufferedData();

            // capture the current mouse state
            mouseState = mouseDevice.CurrentMouseState;

            // store the updated absolute values
            mouseAbsX += mouseState.X;
            mouseAbsY += mouseState.Y;
            mouseAbsZ += mouseState.Z;

            // calc relative deviance from center
            mouseRelX = mouseState.X;
            mouseRelY = mouseState.Y;
            mouseRelZ = mouseState.Z;

            byte[] buttons = mouseState.GetMouseButtons();

            // clear the flags
            mouseButtons = 0;

            for(int i = 0; i < buttons.Length; i++) {
                if((buttons[i] & 0x80) != 0) {
                    mouseButtons |= (1 << i);
                }
            }
        }