Exemplo n.º 1
0
        private void camctlButton_Click(object sender, EventArgs e)
        {
            var       btn       = sender as Button;
            const int anglegain = 10;

            switch (btn.Name.ToString())
            {
            case "btnCamUp":
                if (CamCtl.AngleX - anglegain >= 50)
                {
                    CamCtl.AngleX -= anglegain;
                }
                break;

            case "btnCamDown":
                if (CamCtl.AngleX + anglegain <= 180)
                {
                    CamCtl.AngleX += anglegain;
                }
                break;

            case "btnCamLeft":
                if (CamCtl.AngleY + anglegain <= 180)
                {
                    CamCtl.AngleY += anglegain;
                }
                break;

            case "btnCamRight":
                if (CamCtl.AngleY - anglegain >= 0)
                {
                    CamCtl.AngleY -= anglegain;
                }
                break;

            case "btnCamRst":
                CamCtl.AngleX = 130;
                CamCtl.AngleY = 90;
                break;
            }
            var result = CamCtl.TurnFunc();

            this.lblPostResultInfo.Text = "请求成功 - " + result;
        }
Exemplo n.º 2
0
        public static int KeyBoardHookProc(int nCode, int wParam, IntPtr lParam)
        {
            const int anglegain = 10;

            if (nCode >= 0)
            {
                KeyBoardHookStruct kbh = (KeyBoardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyBoardHookStruct));
                Keys k = (Keys)Enum.Parse(typeof(Keys), kbh.vkCode.ToString());
                switch (k)
                {
                case Keys.Left:
                    if (kbh.flags == 1)
                    {
                        // 这里写按下后做什么事
                        if (CarCtl.CurrentStatus != CarCtl.CarStatus.Up)
                        {
                            CarCtl.TurnFunc("t_left");
                            CarCtl.CurrentStatus = CarCtl.CarStatus.Up;
                        }
                    }
                    else if (kbh.flags == 129)
                    {
                        //放开后做什么事
                        CarCtl.TurnFunc("t_stop");
                        CarCtl.CurrentStatus = CarCtl.CarStatus.Stop;
                    }
                    return(1);

                case Keys.Up:
                    if (kbh.flags == 1)
                    {
                        // 这里写按下后做什么事
                        if (CarCtl.CurrentStatus != CarCtl.CarStatus.Up)
                        {
                            CarCtl.TurnFunc("t_up");
                            CarCtl.CurrentStatus = CarCtl.CarStatus.Up;
                        }
                    }
                    else if (kbh.flags == 129)
                    {
                        //放开后做什么事
                        CarCtl.TurnFunc("t_stop");
                        CarCtl.CurrentStatus = CarCtl.CarStatus.Stop;
                    }
                    return(1);

                case Keys.Right:
                    if (kbh.flags == 1)
                    {
                        if (CarCtl.CurrentStatus != CarCtl.CarStatus.Up)
                        {
                            CarCtl.TurnFunc("t_right");
                            CarCtl.CurrentStatus = CarCtl.CarStatus.Up;
                        }
                    }
                    else if (kbh.flags == 129)
                    {
                        //放开后做什么事
                        CarCtl.TurnFunc("t_stop");
                        CarCtl.CurrentStatus = CarCtl.CarStatus.Stop;
                    }
                    return(1);

                case Keys.Down:
                    if (kbh.flags == 1)
                    {
                        if (CarCtl.CurrentStatus != CarCtl.CarStatus.Up)
                        {
                            CarCtl.TurnFunc("t_down");
                            CarCtl.CurrentStatus = CarCtl.CarStatus.Up;
                        }
                    }
                    else if (kbh.flags == 129)
                    {
                        //放开后做什么事
                        CarCtl.TurnFunc("t_stop");
                        CarCtl.CurrentStatus = CarCtl.CarStatus.Stop;
                    }
                    return(1);

                case Keys.NumPad8:
                    if (kbh.flags == 1)
                    {
                        // 这里写按下后做什么事
                        if (CamCtl.AngleX + anglegain <= 180)
                        {
                            CamCtl.AngleX += anglegain;
                        }
                        CamCtl.TurnFunc();
                    }
                    else if (kbh.flags == 129)
                    {
                        //放开后做什么事
                    }
                    return(1);

                case Keys.NumPad2:
                    if (kbh.flags == 1)
                    {
                        // 这里写按下后做什么事
                        if (CamCtl.AngleX + anglegain >= 0)
                        {
                            CamCtl.AngleX -= anglegain;
                        }
                        CamCtl.TurnFunc();
                    }
                    else if (kbh.flags == 129)
                    {
                        //放开后做什么事
                    }
                    return(1);

                case Keys.NumPad4:
                    if (kbh.flags == 1)
                    {
                        // 这里写按下后做什么事
                        if (CamCtl.AngleY + anglegain <= 180)
                        {
                            CamCtl.AngleY += anglegain;
                        }
                        CamCtl.TurnFunc();
                    }
                    else if (kbh.flags == 129)
                    {
                        //放开后做什么事
                    }
                    return(1);

                case Keys.NumPad6:
                    if (kbh.flags == 1)
                    {
                        // 这里写按下后做什么事
                        if (CamCtl.AngleY + anglegain >= 0)
                        {
                            CamCtl.AngleY -= anglegain;
                        }
                        CamCtl.TurnFunc();
                    }
                    else if (kbh.flags == 129)
                    {
                        //放开后做什么事
                    }
                    return(1);

                default:
                    break;
                }
            }
            return(CallNextHookEx(hHook, nCode, wParam, lParam));
        }