Ejemplo n.º 1
0
        public void Hook_KeyDown(object sender, KeyEventArgs e)
        {
            LogHelper.ShowLog("keyDown: {0}", e.KeyCode);

            // 游戏运行执行逻辑 globalParam.runGame
            if (true)
            {
                if (e.KeyCode.ToString().Equals(anjianViewModel.KeyDiscern))
                {
                    // ~ 按键
                    // 执行识别枪械
                }
                else if (e.KeyValue == 9)
                {
                    // ValiOpenBag();
                    imageSelectWeapon.ValiLogic();
                }
                else if (e.KeyCode.ToString().Equals(anjianViewModel.KeyLogic))
                {
                    player.runLogic = !player.runLogic;
                    string runLogicSpeak = "开启";
                    if (!player.runLogic)
                    {
                        runLogicSpeak = "关闭";
                    }
                    SpeechSynthesizer synthes = new SpeechSynthesizer();
                    synthes.Speak(runLogicSpeak);//异步
                    LogHelper.ShowLog("开启/关闭压枪");
                }
                else if (e.KeyCode.ToString().Equals(anjianViewModel.KeySpeaker))
                {
                    if (!_speakStatus)
                    {
                        _speakStatus = true;
                        // 读取装备信息 TTS
                        Task.Run(() =>
                        {
                            string textToSpeak        = "武器一:" + playerViewModel.weapon0 + "," + playerViewModel.scope0 + "," + playerViewModel.qiangkou0 + "," + playerViewModel.woBa0 + "," + playerViewModel.magazine0 + "," + playerViewModel.qiangTuo0;
                            SpeechSynthesizer synthes = new SpeechSynthesizer();
                            synthes.Speak(textToSpeak);//异步
                            _speakStatus = false;
                        });
                    }
                }
                else if (e.KeyCode.ToString().Equals(anjianViewModel.KeyShouQiang))
                {
                    // X 按键
                    // 查询是否需要关闭压枪
                    player.XDown = !player.XDown;
                }
                else if (e.KeyValue == 49)
                {
                    // 1 按键
                    if (player.useMissiles)
                    {
                        player.useMissiles = false;
                    }
                    if (!player.weapon0.weapon.Equals("空"))
                    {
                        player.useWeapon = player.weapon0;
                    }
                    gunsViewModel.Refresh();
                    playerViewModel.Refresh();
                }
                else if (e.KeyValue == 50)
                {
                    // 2 按键
                    if (player.useMissiles)
                    {
                        player.useMissiles = false;
                    }
                    if (!player.weapon1.weapon.Equals("空"))
                    {
                        player.useWeapon = player.weapon1;
                    }
                    gunsViewModel.Refresh();
                    playerViewModel.Refresh();
                }
                else if (e.KeyValue == 30)
                {
                }
                else if (e.KeyCode.ToString().Equals(anjianViewModel.KeyDun))
                {
                    // C 按键
                    if (player.position.Equals("站") || player.position.Equals("趴"))
                    {
                        gunsViewModel.Position = "蹲";
                    }
                    else
                    {
                        gunsViewModel.Position = "站";
                    }
                    playerViewModel.RaisePropertyChanged("position");
                    // 刷新武器
                    imageSelectWeapon.GetWeaponData(player.useWeapon);
                    gunsViewModel.RaisePropertyChanged("Datas");
                    LogHelper.ShowLog("姿势:{0}", player.position);
                }
                else if (e.KeyCode.ToString().Equals(anjianViewModel.KeyPa))
                {
                    if (player.position.Equals("站") || player.position.Equals("蹲"))
                    {
                        gunsViewModel.Position = "趴";
                    }
                    else
                    {
                        gunsViewModel.Position = "站";
                    }
                    playerViewModel.RaisePropertyChanged("position");
                    // 刷新武器
                    imageSelectWeapon.GetWeaponData(player.useWeapon);
                    gunsViewModel.RaisePropertyChanged("Datas");
                    LogHelper.ShowLog("姿势:{0}", player.position);
                }
                else if (e.KeyCode.ToString().Equals(anjianViewModel.KeyTiao))
                {
                    if (!player.position.Equals("站"))
                    {
                        gunsViewModel.Position = "站";
                        playerViewModel.RaisePropertyChanged("position");
                        // 刷新武器
                        imageSelectWeapon.GetWeaponData(player.useWeapon);
                        gunsViewModel.RaisePropertyChanged("Datas");
                        LogHelper.ShowLog("姿势:{0}", player.position);
                    }
                }
                else if (e.KeyValue == 27)
                {
                    // ESC 按键
                    player.ESCDown = !player.ESCDown;
                }
                else if (e.KeyCode.ToString().Equals(anjianViewModel.KeyDiuLei1) || e.KeyCode.ToString().Equals(anjianViewModel.KeyDiuLei2) ||
                         e.KeyCode.ToString().Equals(anjianViewModel.KeyDiuLei3))
                {
                    player.useMissiles = true;
                }
                else if (e.KeyValue == 82)
                {
                    // R 按键
                    if (player.useMissiles && mouseStatus.leftDown && jichuViewModel.NieLei)
                    {
                        LogHelper.ShowLog("丢雷倒计时");
                        SoundPlayer player = new SoundPlayer(Properties.Resources.NieLei);
                        player.Play();
                    }
                }
                else if (e.KeyValue == 116)
                {
                }
            }

            if (e.KeyCode.ToString().Equals(anjianViewModel.KeyHSMainWindow))
            {
                // 隐藏/显示主窗口
                if (globalParam.MainWindow.IsActive)
                {
                    globalParam.MainWindow.Hide();
                    _List.ProcessName = Process.GetCurrentProcess().ProcessName + ".exe";
                    _List.Star();
                }
                else
                {
                    globalParam.MainWindow.Show();
                    _List.Stop();
                }
            }
            else if (e.KeyCode.ToString().Equals(anjianViewModel.KeyHSPlayerInfo))
            {
                lock (singleton_Lock)
                {
                    if (null == globalParam.PlayerWin)
                    {
                        globalParam.PlayerWin = new PlayerInfoWindow();
                    }
                    if (!globalParam.topWindow)
                    {
                        globalParam.PlayerWin.Left = 0;
                        globalParam.PlayerWin.Top  = globalParam.ScreenHeight / 2;
                        globalParam.PlayerWin.Show();
                        TopMostTool.setTopCustomBar("PlayerInfoWindow");
                        globalParam.PlayerWin.Topmost = true;
                    }
                    else
                    {
                        globalParam.PlayerWin.Topmost = false;
                        TopMostTool.setTopCustomBar("PlayerInfoWindow");
                        globalParam.PlayerWin.Hide();
                    }
                    globalParam.topWindow = !globalParam.topWindow;
                }
            }
        }
Ejemplo n.º 2
0
        public void ValiLogic()
        {
            // 识别颜色
            DateTime startTime = DateTime.Now;

            if (!ValiOpenBag())
            {
                return;
            }

            string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "data/");

            if (System.IO.Directory.Exists(path) == false)//如果不存在就创建file文件夹
            {
                System.IO.Directory.CreateDirectory(path);
            }
            string name  = "";
            string name1 = "";

            Bitmap image  = new Bitmap(globalParam.weapon0Location["basicSize"].X, globalParam.weapon0Location["basicSize"].Y);
            Bitmap image1 = new Bitmap(globalParam.weapon1Location["basicSize"].X, globalParam.weapon1Location["basicSize"].Y);

            Graphics imgGraphics = Graphics.FromImage(image);

            imgGraphics.CopyFromScreen(globalParam.weapon0Location["basic"], new Point(0, 0), new Size(image.Width, image.Height)); //第一个参数是截图开始坐标,第二个参数是要拷贝到的Bitmap的开始位置,保持不变,最后是图片大小
            if (BaseConfig.DEBUG)
            {
                image.Save(path + Guid.NewGuid().ToString() + ".png");
            }
            name = path + GetRandomString(9, true, true, false, false, null);
            CutImage(image, name + ".png");

            Graphics imgGraphics1 = Graphics.FromImage(image1);

            imgGraphics1.CopyFromScreen(globalParam.weapon1Location["basic"], new Point(0, 0), new Size(image1.Width, image1.Height)); //第一个参数是截图开始坐标,第二个参数是要拷贝到的Bitmap的开始位置,保持不变,最后是图片大小
            if (BaseConfig.DEBUG)
            {
                image1.Save(path + Guid.NewGuid().ToString() + ".png");
            }
            name1 = path + GetRandomString(10, true, true, false, false, null);
            CutImage(image1, name1 + ".png");

            try
            {
                string lastWeaponName0 = player.weapon0.weapon;
                string lastWeaponName1 = player.weapon1.weapon;
                string useWeaponName   = player.useWeapon.weapon;

                string weaponName = GetOCRWeapon(name + ".png");

                if (!String.IsNullOrEmpty(weaponName))
                {
                    // 配件信息
                    Dictionary <string, string> other = QueryAccessories(globalParam.weapon0Location, image);

                    player.weapon0.weapon = weaponName;
                    if (null != other)
                    {
                        player.weapon0.qiangkou = other["qiangkou"];
                        player.weapon0.woBa     = other["woBa"];
                        player.weapon0.magazine = other["magazine"];
                        player.weapon0.qiangTuo = other["qiangTuo"];
                        player.weapon0.scope    = other["scope"];
                        GetWeaponData(player.weapon0);
                        if (player.useWeapon.weapon.Equals("空"))
                        {
                            player.useWeapon = player.weapon0;
                        }
                    }
                }
                else
                {
                    player.weapon0.ClearAttr();
                }

                string weaponName1 = GetOCRWeapon(name1 + ".png");

                if (!String.IsNullOrEmpty(weaponName1))
                {
                    // 配件信息
                    Dictionary <string, string> other = QueryAccessories(globalParam.weapon1Location, image1);

                    player.weapon1.weapon = weaponName1;
                    if (null != other)
                    {
                        player.weapon1.qiangkou = other["qiangkou"];
                        player.weapon1.woBa     = other["woBa"];
                        player.weapon1.magazine = other["magazine"];
                        player.weapon1.qiangTuo = other["qiangTuo"];
                        player.weapon1.scope    = other["scope"];
                        GetWeaponData(player.weapon1);
                        if (player.useWeapon.weapon.Equals("空"))
                        {
                            player.useWeapon = player.weapon1;
                        }
                    }
                }
                else
                {
                    player.weapon1.ClearAttr();
                }

                if (!String.IsNullOrEmpty(weaponName) || !String.IsNullOrEmpty(weaponName1))
                {
                    // 交换武器位置识别
                    if (useWeaponName.Equals(weaponName) && lastWeaponName0.Equals(weaponName1) && lastWeaponName1.Equals(weaponName))
                    {
                        player.useWeapon = player.weapon0;
                    }
                    else if (useWeaponName.Equals(weaponName1) && lastWeaponName0.Equals(weaponName1) && lastWeaponName1.Equals(weaponName))
                    {
                        player.useWeapon = player.weapon1;
                    }

                    if (String.IsNullOrEmpty(weaponName) && !String.IsNullOrEmpty(weaponName1))
                    {
                        player.useWeapon = player.weapon1;
                    }
                    else if (!String.IsNullOrEmpty(weaponName) && String.IsNullOrEmpty(weaponName1))
                    {
                        player.useWeapon = player.weapon0;
                    }

                    if (jichuViewModel.Speaker && !_speakerStatus)
                    {
                        _speakerStatus = true;
                        Task.Run(() =>
                        {
                            SpeechSynthesizer synthes = new SpeechSynthesizer();
                            synthes.Speak("识别成功");//异步
                            _speakerStatus = false;
                        });
                    }
                }
                playerViewModel.Refresh();
                gunsViewModel.Refresh();
            }
            catch (Exception ex)
            {
                LogHelper.ShowLog("识别枪械报错 错误信息: {0}", ex.Message);
            }

            LogHelper.ShowLog("枪械识别耗时: {0}", (DateTime.Now - startTime).ToString());
        }