public override void FirstCheckState(ref Microsoft.DirectX.DirectInput.JoystickState controllerState)
        {
            bool s = (controllerState.GetButtons()[Index] & 0x80) == 0x80;

            _state = !s;
            CheckState(ref controllerState);
        }
Ejemplo n.º 2
0
        public override void CheckState(ref Microsoft.DirectX.DirectInput.JoystickState controllerState)
        {
            bool s = (controllerState.GetButtons()[Index] & 0x80) == 0x80;

            if (s)
            {
                if (!_repeating)
                {
                    _state          = s;
                    _repeatingState = _state;
                    OnChangeValue(_state);
                    _repeating = true;
                    _timer.Change(RepeatAfter, System.Threading.Timeout.Infinite);
                }
            }
            else
            {
                if (_repeating || _state)
                {
                    _repeating = false;
                    _timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
                    _state = s;
                    OnChangeValue(_state);
                }
            }
        }
        public override void CheckState(ref Microsoft.DirectX.DirectInput.JoystickState controllerState)
        {
            bool s = (controllerState.GetButtons()[Index] & 0x80) == 0x80;

            if (_state != s)
            {
                _state = s;
                OnChangeValue(_state);
            }
        }
Ejemplo n.º 4
0
        //* -----------------------------------------------------------------------*
        /// <summary>入力状態更新のスレッドです。</summary>
        ///
        /// <returns>スレッドが実行される間、<c>true</c></returns>
        private IEnumerator <object> threadStateReflesh()
        {
            while (true)
            {
                yield return(null);

                bool[] bState = new bool[BUTTON_STATE.Length];
#if WINDOWS
                KeyboardState stateKey =
                    Keyboard.GetState();
                for (int i = 0; i < bState.Length; i++)
                {
                    bState[i] = stateKey.IsKeyDown(assignKeyboard[i]);
                }
                if (legacy != null)
                {
                    Microsoft.DirectX.DirectInput.JoystickState legacystate = legacy.state;
                    byte[] buttons = legacystate.GetButtons();
                    bState[(int)EDirection.up]    = bState[(int)EDirection.up] || (legacystate.Y < -600);
                    bState[(int)EDirection.down]  = bState[(int)EDirection.down] || (legacystate.Y > 600);
                    bState[(int)EDirection.left]  = bState[(int)EDirection.left] || (legacystate.X < -600);
                    bState[(int)EDirection.right] = bState[(int)EDirection.right] || (legacystate.X > 600);
                    for (int i = (int)EDirection.__reserved; i < bState.Length; i++)
                    {
                        int nButtonID = assignLegacy[i - (int)EDirection.__reserved];
                        bState[i] = bState[i] ||
                                    (buttons.Length > nButtonID && buttons[nButtonID] != 0);
                    }
                }
#else
                for (int i = 0; i < bState.Length; bState[i++] = false)
                {
                    ;
                }
#endif
                if (isUseXBOX360GamePad)
                {
                    GamePadState stateButton = GamePad.GetState(PlayerIndex.One);
                    Vector2      leftStick   = stateButton.ThumbSticks.Left;
                    if (leftStick.Length() > 0.7f)
                    {
                        double dAngle = Math.Atan2(leftStick.Y, leftStick.X);
                        bState[(int)EDirection.up]    = bState[(int)EDirection.up] || (dAngle <= MathHelper.PiOver4 * 3.5 && dAngle >= MathHelper.PiOver4 * 0.5);
                        bState[(int)EDirection.down]  = bState[(int)EDirection.down] || (dAngle >= MathHelper.PiOver4 * -3.5 && dAngle <= MathHelper.PiOver4 * -0.5);
                        bState[(int)EDirection.left]  = bState[(int)EDirection.left] || Math.Abs(dAngle) >= MathHelper.PiOver4 * 2.5;
                        bState[(int)EDirection.right] = bState[(int)EDirection.right] || Math.Abs(dAngle) <= MathHelper.PiOver4 * 1.5;
                    }
                    else
                    {
                        bState[(int)EDirection.up]    = bState[(int)EDirection.up] || stateButton.IsButtonDown(Buttons.DPadUp);
                        bState[(int)EDirection.down]  = bState[(int)EDirection.down] || stateButton.IsButtonDown(Buttons.DPadDown);
                        bState[(int)EDirection.left]  = bState[(int)EDirection.left] || stateButton.IsButtonDown(Buttons.DPadLeft);
                        bState[(int)EDirection.right] = bState[(int)EDirection.right] || stateButton.IsButtonDown(Buttons.DPadRight);
                    }
                    for (int i = (int)EDirection.__reserved; i < bState.Length; i++)
                    {
                        bState[i] = bState[i] || stateButton.IsButtonDown(assignXBOX360[i - (int)EDirection.__reserved]);
                    }
                }
                for (int i = 0; i < bState.Length; i++)
                {
                    BUTTON_STATE[i].refresh(bState[i]);
                }
            }
        }