private void Xbox(GamePadState gamePadState)
        {
            // 移动
            Diablo.Move(
                leftH.IsChecked.Value ? -gamePadState.ThumbSticks.Left.X : gamePadState.ThumbSticks.Left.X,
                leftZ.IsChecked.Value ? gamePadState.ThumbSticks.Left.Y : -gamePadState.ThumbSticks.Left.Y,
                stand,
                (int)slider1.Value,
                (int)slider2.Value);
            Diablo.MouseMove(
                rightH.IsChecked.Value ? -gamePadState.ThumbSticks.Right.X : gamePadState.ThumbSticks.Right.X,
                rightZ.IsChecked.Value ? gamePadState.ThumbSticks.Right.Y : -gamePadState.ThumbSticks.Right.Y);

            // 普通攻击
            if (gamePadState.Buttons.A == ButtonState.Pressed)
            {
                Diablo.MouseLeftDown(ref left);
            }
            else
            {
                Diablo.MouseLeftUp(ref left);
            }


            // 特殊攻击
            if (gamePadState.Buttons.B == ButtonState.Pressed)
            {
                Diablo.MouseRightDown(ref right);
            }
            else
            {
                Diablo.MouseRightUp(ref right);
            }

            // 1234
            if (gamePadState.Buttons.X == ButtonState.Pressed)
            {
                Diablo.Key1(ref key1);
            }
            else
            {
                key1 = false;
            }

            if (gamePadState.Buttons.Y == ButtonState.Pressed)
            {
                Diablo.Key2(ref key2);
            }
            else
            {
                key2 = false;
            }

            // 站立攻击
            if (gamePadState.Triggers.Left > 0.5)
            {
                Diablo.StandDown(ref stand);
            }
            else
            {
                Diablo.StandUp(ref stand);
            }

            if (gamePadState.Buttons.RightShoulder == ButtonState.Pressed)
            {
                Diablo.Key3(ref key3);
            }
            else
            {
                key3 = false;
            }
            if (gamePadState.Triggers.Right > 0.5)
            {
                Diablo.Key4(ref key4);
            }
            else
            {
                key4 = false;
            }

            // 喝血瓶
            if (gamePadState.Buttons.LeftShoulder == ButtonState.Pressed)
            {
                Diablo.KeyQ(ref key6);
            }
            else
            {
                key6 = false;
            }


            if (gamePadState.DPad.Up == ButtonState.Pressed)
            {
                Diablo.KeyM(ref key7);
            }
            else
            {
                key7 = false;
            }

            if (gamePadState.DPad.Down == ButtonState.Pressed)
            {
                Diablo.KeyX(ref key8);
            }
            else
            {
                key8 = false;
            }

            if (gamePadState.DPad.Left == ButtonState.Pressed)
            {
                Diablo.KeyT(ref key9);
            }
            else
            {
                key9 = false;
            }

            if (gamePadState.DPad.Right == ButtonState.Pressed)
            {
                Diablo.KeyI(ref key10);
            }
            else
            {
                key10 = false;
            }

            // 重置血量监视点
            if (gamePadState.Buttons.Back == ButtonState.Pressed)
            {
                bloodLeft   = System.Windows.Forms.Control.MousePosition.X;
                bloodHeight = (int)SystemParameters.PrimaryScreenHeight - System.Windows.Forms.Control.MousePosition.Y;

                if (bloodHeight > 200)
                {
                    MessageBox.Show("请将鼠标指在左下方血量球的上边框再按BACK键!");
                    bloodHeight = 160;
                }

                textBox1.Text = bloodLeft + ",-" + bloodHeight;
            }
        }
        private void TestController()
        {
            gamePadState = GamePad.GetState(0);
            // 优先判断360控制器
            if (gamePadState.IsConnected)
            {
                if (controllerType != 1)
                {
                    image1.Source       = new BitmapImage(new Uri(@"xbox.png", UriKind.RelativeOrAbsolute));
                    controllerType      = 1;
                    this.Title          = "暗黑破坏神3控制器(已连接XBOX游戏控制器)";
                    checkBox1.IsEnabled = true;
                }
                Xbox(gamePadState);
            }
            else
            {
                // 判断其他控制器
                int result = JoyAPI.joyGetPosEx(0, ref infoEx);

                if (result == 0)
                {
                    if (controllerType != 2)
                    {
                        image1.Source       = new BitmapImage(new Uri(@"other.png", UriKind.RelativeOrAbsolute));
                        controllerType      = 2;
                        this.Title          = "暗黑破坏神3控制器(已连接普通游戏控制器)";
                        checkBox1.IsEnabled = false;
                        checkBox1.IsChecked = false;
                    }


                    // 移动
                    Diablo.Move(
                        leftH.IsChecked.Value ? -newXY(infoEx.dwXpos) : newXY(infoEx.dwXpos),
                        leftZ.IsChecked.Value ? -newXY(infoEx.dwYpos) : newXY(infoEx.dwYpos),
                        stand,
                        (int)slider1.Value,
                        (int)slider2.Value);
                    Diablo.MouseMove(
                        rightH.IsChecked.Value ? -newXY(infoEx.dwRpos) : newXY(infoEx.dwRpos),
                        rightZ.IsChecked.Value ? -newXY(infoEx.dwZpos) : newXY(infoEx.dwZpos));

                    if ((infoEx.dwButtons & JoyAPI.JOY_BUTTON3) == JoyAPI.JOY_BUTTON3)
                    {
                        Diablo.MouseLeftDown(ref left);
                    }
                    else
                    {
                        Diablo.MouseLeftUp(ref left);
                    }

                    if ((infoEx.dwButtons & JoyAPI.JOY_BUTTON2) == JoyAPI.JOY_BUTTON2)
                    {
                        Diablo.MouseRightDown(ref right);
                    }
                    else
                    {
                        Diablo.MouseRightUp(ref right);
                    }


                    if ((infoEx.dwButtons & JoyAPI.JOY_BUTTON4) == JoyAPI.JOY_BUTTON4)
                    {
                        Diablo.Key1(ref key1);
                    }
                    else
                    {
                        key1 = false;
                    }
                    if ((infoEx.dwButtons & JoyAPI.JOY_BUTTON1) == JoyAPI.JOY_BUTTON1)
                    {
                        Diablo.Key2(ref key2);
                    }
                    else
                    {
                        key2 = false;
                    }

                    // 站立攻击
                    if ((infoEx.dwButtons & JoyAPI.JOY_BUTTON7) == JoyAPI.JOY_BUTTON7)
                    {
                        Diablo.StandDown(ref stand);
                    }
                    else
                    {
                        Diablo.StandUp(ref stand);
                    }

                    if ((infoEx.dwButtons & JoyAPI.JOY_BUTTON6) == JoyAPI.JOY_BUTTON6)
                    {
                        Diablo.Key4(ref key4);
                    }
                    else
                    {
                        key4 = false;
                    }
                    if ((infoEx.dwButtons & JoyAPI.JOY_BUTTON8) == JoyAPI.JOY_BUTTON8)
                    {
                        Diablo.Key3(ref key3);
                    }
                    else
                    {
                        key3 = false;
                    }

                    if ((infoEx.dwButtons & JoyAPI.JOY_BUTTON5) == JoyAPI.JOY_BUTTON5)
                    {
                        Diablo.KeyQ(ref key5);
                    }
                    else
                    {
                        key5 = false;
                    }

                    // 重置血量监视点
                    if ((infoEx.dwButtons & JoyAPI.JOY_BUTTON9) == JoyAPI.JOY_BUTTON9)
                    {
                        bloodLeft   = System.Windows.Forms.Control.MousePosition.X;
                        bloodHeight = (int)SystemParameters.PrimaryScreenHeight - System.Windows.Forms.Control.MousePosition.Y;

                        if (bloodHeight > 200)
                        {
                            MessageBox.Show("请将鼠标指在左下方血量球的上边框再按BACK键!");
                            bloodHeight = 160;
                        }

                        textBox1.Text = bloodLeft + ",-" + bloodHeight;
                    }


                    if (infoEx.dwPOV == JoyAPI.JOY_BUTTONUP)
                    {
                        // 上
                        Diablo.KeyM(ref key7);
                    }
                    else
                    {
                        key7 = false;
                    }

                    if (infoEx.dwPOV == JoyAPI.JOY_BUTTONDOWN)
                    {
                        // 下
                        Diablo.KeyX(ref key8);
                    }
                    else
                    {
                        key8 = false;
                    }

                    if (infoEx.dwPOV == JoyAPI.JOY_BUTTONLEFT)
                    {
                        // 左
                        Diablo.KeyT(ref key9);
                    }
                    else
                    {
                        key9 = false;
                    }

                    if (infoEx.dwPOV == JoyAPI.JOY_BUTTONRIGHT)
                    {
                        // 右
                        Diablo.KeyI(ref key10);
                    }
                    else
                    {
                        key10 = false;
                    }
                }
                else
                {
                    image1.Source       = new BitmapImage(new Uri(@"null.png", UriKind.RelativeOrAbsolute));
                    controllerType      = 0;
                    this.Title          = "暗黑破坏神3控制器(未连接游戏控制器)";
                    checkBox1.IsEnabled = false;
                    checkBox1.IsChecked = false;
                }
            }
        }