Example #1
0
        private void BeginSearch(object sender, FrameLoadEndEventArgs args)
        {
            if (browser.Address == ConstParameter.SEARCH_ENGINES && _is_working && _currentNum <= CommonParameter.ConfigParam.loop_count)
            {
                if (_currentIndex < CommonParameter.ConfigParam.key_match_list.Count)
                {
                    // 移动到搜索框
                    int _x = CommonParameter.FormX + ConstParameter.SearchX + ConstParameter.RandomSeed.Next(50, 300);
                    int _y = CommonParameter.FormY + ConstParameter.BrowerY + ConstParameter.SearchY + ConstParameter.RandomSeed.Next(15, 20);
                    Task.Factory.StartNew(() =>
                    {
                        Monitor.Enter(CommonParameter.LokerObj); // 开始 搜索,需要锁定
                        var sim = new InputSimulator();
                        sim.Mouse
                        .MoveMouseTo(CommonParameter.CurrentScreenWidth * _x, CommonParameter.CurrentScreenHeight * _y)
                        .Sleep(CommonParameter.ConfigParam.simulate_speed.mouse_move_search_input.ToRandom())
                        .LeftButtonClick()
                        .Sleep(CommonParameter.ConfigParam.simulate_speed.mouse_click_search_input.ToRandom());
                        // 输入 搜索关键字
                        foreach (char _single in CommonParameter.ConfigParam.key_match_list[_currentIndex].Key)
                        {
                            sim.Keyboard
                            .TextEntry(_single)
                            .Sleep(CommonParameter.ConfigParam.simulate_speed.keyboard_keywords_speed.ToRandom());
                        }

                        sim.Keyboard.KeyPress(VirtualKeyCode.RETURN); // 按下回车键

                        Monitor.Pulse(CommonParameter.LokerObj);
                        Monitor.Exit(CommonParameter.LokerObj); // 输入搜索完成
                    });
                }
                else
                {
                    // 用于判断最后一次
                    if (_is_working && _currentNum >= CommonParameter.ConfigParam.loop_count)
                    {
                        OnExcuteClickEnd(this, null);
                        return;
                    }
                    var _msg = CommonFunction.BackgroundDoWorkIpelfFast();
                    if (!string.IsNullOrEmpty(_msg))
                    {
                        MessageBox.Show(_msg, "IP精灵异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    _currentNum++;
                    OnExitApplcation(null, null);
                }
            }
        }