Exemple #1
0
        /// <summary>
        /// 点击按钮,先按下按钮不松开,然后观察按钮是否发生样式变化;如果
        /// 没有发生变化,则一段时间后再次检查,直到发生变化后才松开按钮,形成一次
        /// 点击事件。如果按下很长时间都没有发生变化,则认为手机模拟器卡死。
        /// </summary>
        /// <param name="ClickRange">观察范围</param>
        public static void ClickBtn(Rectangle ClickRange)
        {
            Bitmap Before = ImageHandleHelper.CopyScreen(ClickRange);
            Bitmap After;

            for (int i = 0; i < 200; i++)
            {
                if (OpencvImageHelper.CheckChange(ClickRange, 4))
                {
                    if (i % 10 == 0)
                    {
                        MouseClick(MouseClickType.LeftPress);
                    }
                    if (OpencvImageHelper.Compare2Images(Before, After = ImageHandleHelper.CopyScreen(ClickRange), 0) != 0)
                    {
                        Before.Dispose();
                        Before = After;
                        MouseClick(MouseClickType.LeftRelease);
                        break;
                    }
                    After.Dispose();
                }
            }
            for (int i = 0; i < 200; i++)
            {
                if (OpencvImageHelper.CheckChange(ClickRange, 4))
                {
                    using (Before) { }
                    return;
                }
            }
            MouseMove(ClickRange.X > ClickRange.Width ? 0 : ClickRange.X + ClickRange.Width + 1000, 0);
            MouseClick(MouseClickType.LeftRelease);
            throw new Exception("界面卡死。。(ERROR:-999)");
        }