示例#1
0
        private void PollGamepad(object sender, ElapsedEventArgs e)
        {
            if(Dispatcher.CheckAccess())
            {
                GamepadState current = new GamepadState(SlimDX.XInput.UserIndex.One);
                current.Update();
                if (!current.Equals(gpMonitor))
                {
                    RoutedEvent routedEvent = Keyboard.KeyDownEvent;
                    Key key = Key.None;

                    if (current.DPad.Left) key = Key.Left;
                    if (current.DPad.Right) key = Key.Right;
                    if (current.DPad.Up) key = Key.Up;
                    if (current.DPad.Down) key = Key.Down;
                    if (current.A || current.Start) key = Key.Enter;

                    if (key != Key.None)
                    {
                        if (Keyboard.PrimaryDevice.ActiveSource != null)
                        {
                            InputManager.Current.ProcessInput(
                            new KeyEventArgs(
                                Keyboard.PrimaryDevice,
                                Keyboard.PrimaryDevice.ActiveSource,
                                0,
                                key
                                ) { RoutedEvent = routedEvent }
                            );
                        }

                        if (haptic) current.Vibrate(1f, 1f, 100);
                    }

                    gpMonitor = current;
                }
            }
            else
            {
                Dispatcher.BeginInvoke(
                    new PollGamepadDelegate(PollGamepad),
                    new object[] { sender, e }
                );
            }
        }
示例#2
0
        public bool Equals(GamepadState gp)
        {
            if ((Object)gp == null) return false;

            return (
                this.UserIndex == gp.UserIndex &&
                this.A == gp.A &&
                this.B == gp.B &&
                this.X == gp.X &&
                this.Y == gp.Y &&
                this.DPad.Up == gp.DPad.Up &&
                this.DPad.Down == gp.DPad.Down &&
                this.DPad.Left == gp.DPad.Left &&
                this.DPad.Right == gp.DPad.Right &&
                this.LeftShoulder == gp.LeftShoulder &&
                this.LeftTrigger == gp.LeftTrigger &&
                this.LeftStick.Clicked == gp.LeftStick.Clicked &&
                this.LeftStick.Position.X == gp.LeftStick.Position.X &&
                this.LeftStick.Position.Y == gp.LeftStick.Position.Y &&
                this.RightShoulder == gp.RightShoulder &&
                this.RightTrigger == gp.RightTrigger &&
                this.RightStick.Clicked == gp.RightStick.Clicked &&
                this.RightStick.Position.X == gp.RightStick.Position.X &&
                this.RightStick.Position.Y == gp.RightStick.Position.Y &&
                this.Back == gp.Back &&
                this.Start == gp.Start
                );
        }