Esempio n. 1
0
        public static GamePad GetPadState(int nUserIdx)
        {
            XINPUT_STATE st = new XINPUT_STATE();
            unsafe
            {
                if (XInputGetState(nUserIdx, &st) != 0)
                    return null;
            }

            GamePad gp = new GamePad();
            gp.dwPacketNumber = st.dwPacketNumber;
            gp.Buttons = st.Gamepad.wButtons;
            gp.LeftTrigger = apply_thresh(st.Gamepad.bLeftTrigger, XInput.TriggerThresh, XInput.TriggerMax);
            gp.RightTrigger = apply_thresh(st.Gamepad.bRightTrigger, XInput.TriggerThresh, XInput.TriggerMax);
            //if (m_settings.LThumbToDPad)
            //{
                gp.ThumbL = apply_thresh_2d(st.Gamepad.sThumbLX, st.Gamepad.sThumbLY, XInput.LeftThumbThresh, XInput.ThumbstickMax);
                gp.ThumbR = apply_thresh_2d(st.Gamepad.sThumbRX, st.Gamepad.sThumbRY, XInput.RightThumbThresh, XInput.ThumbstickMax);
            /*}
            else
            {
                gp.ThumbL = apply_thresh_2d(st.Gamepad.sThumbLX, st.Gamepad.sThumbLY, XInput.LeftThumbThresh, XInput.ThumbstickMax);
                gp.ThumbR = apply_thresh_2d(st.Gamepad.sThumbRX, st.Gamepad.sThumbRY, XInput.RightThumbThresh, XInput.ThumbstickMax);
            }*/
            return gp;
        }
Esempio n. 2
0
        private void AnalogMovement(GamePad g)
        {
            float x = 0f;
            float y = 0f;
            if (m_settings.SwapSticks)
            {
                x = g.ThumbR.X;
                y = g.ThumbR.Y;
            }
            else
            {
                x = g.ThumbL.X;
                y = g.ThumbL.Y;
            }
            if (x > 0.5f)
            {
                FakeKey(Keys.E, KeyPressType.Down); // Strife Right
                m_btnEDown = true;
            }
            else if (x < -0.5f)
            {
                FakeKey(Keys.Q, KeyPressType.Down); // Strife Left
                m_btnQDown = true;
            }
            else
            {
                // Send up keys to stop moving if no input
                if (m_btnEDown)
                {
                    FakeKey(Keys.E, KeyPressType.Up);
                    m_btnEDown = false;
                }
                if (m_btnQDown)
                {
                    FakeKey(Keys.Q, KeyPressType.Up);
                    m_btnQDown = false;
                }
            }
            if (y > 0.5f)
            {
                FakeKey(Keys.W, KeyPressType.Down); // Move Forward
                m_btnWDown = true;
            }
            else if (y < -0.5f)
            {
                FakeKey(Keys.S, KeyPressType.Down); // Move Backwards
                m_btnSDown = true;
            }
            else
            {
                // Send up keys to stop moving if no input
                if (m_btnWDown)
                {
                    FakeKey(Keys.W, KeyPressType.Up);
                    m_btnWDown = false;
                }
                if (m_btnSDown)
                {
                    FakeKey(Keys.S, KeyPressType.Up);
                    m_btnSDown = false;
                }
            }

            // Evaluate if the left and right triggers are pulled as shift modifiers.
            m_RTriggerDown = (g.RightTrigger > 0.5f) ? true : false;
            m_LTriggerDown = (g.LeftTrigger > 0.5f) ? true : false;
        }
Esempio n. 3
0
        private void ControllerPollThread()
        {
            while (!m_done)
            {
                // sleep for a bit
                Thread.Sleep(20);

                // only check the selected controller
                GamePad gp = XInput.GetPadState(m_nPadIndex);
                if (gp == null)
                    continue; // no game pad in this slot

                // Handle the preference for left or right target mode.
                if (m_settings.SwapShiftAndTarget)
                {
                    if ((gp.Buttons & GamePad.BTN_RIGHT_SHOULDER) != 0)
                        gp.Buttons |= BTN_TARGET;
                    if ((gp.Buttons & GamePad.BTN_LEFT_SHOULDER) != 0)
                        gp.Buttons |= BTN_SHIFT;
                }
                else
                {
                    if ((gp.Buttons & GamePad.BTN_RIGHT_SHOULDER) != 0)
                        gp.Buttons |= BTN_SHIFT;
                    if ((gp.Buttons & GamePad.BTN_LEFT_SHOULDER) != 0)
                        gp.Buttons |= BTN_TARGET;
                }

                // update the "mouse" using the analog sticks
                UpdateMouseMove(gp);
                // Grab our analog values from the controller
                AnalogMovement(gp);

                // check for button changes
                UInt32 BtnDown = gp.Buttons & ~m_pad.Buttons;
                UInt32 BtnUp = ~gp.Buttons & m_pad.Buttons;

                // update the pad and handle changes
                if (BtnUp != 0)
                {
                    OnButton(BtnUp, KeyPressType.Up);
                }
                m_pad = gp;
                if (BtnDown != 0)
                {
                    OnButton(BtnDown, KeyPressType.Down);
                }
            }
        }
Esempio n. 4
0
        private void UpdateMouseMove(GamePad now)
        {
            Vector2 zero = new Vector2(0.0f, 0.0f);

            if (m_settings.SwapSticks)
            {
                if ((now.Buttons & BTN_SHIFT) != 0) // mousemove -  //was GamePad.BTN_RIGHT_SHOULDER
                    FakeMouseMove((int)(now.ThumbL.X * Math.Abs(now.ThumbL.X) * m_mouseSensMulti), (int)(now.ThumbL.Y * Math.Abs(now.ThumbL.Y) * -m_mouseSensMulti));
                else if (!(now.ThumbL == zero) && m_fRMouseDown) // mouselook
                    FakeMouseMove((int)(now.ThumbL.X * m_lookSensMulti), (int)(now.ThumbL.Y * -m_lookSensMulti));
            }
            else
            {
                // move the mouse
                if ((now.Buttons & BTN_SHIFT) != 0) // mousemove -  //was GamePad.BTN_RIGHT_SHOULDER
                    FakeMouseMove((int)(now.ThumbR.X * Math.Abs(now.ThumbR.X) * m_mouseSensMulti), (int)(now.ThumbR.Y * Math.Abs(now.ThumbR.Y) * -m_mouseSensMulti));
                else if (!(now.ThumbR == zero) && m_fRMouseDown) // mouselook
                    FakeMouseMove((int)(now.ThumbR.X * m_lookSensMulti), (int)(now.ThumbR.Y * -m_lookSensMulti));
            }
        }