Beispiel #1
0
        /// <summary>
        /// 获取当前设备的数量
        /// </summary>
        /// <returns></returns>
        public static int GetDeviceNum()
        {
            using (Process process = CmdUtils.createCmd())
            {
                process.StandardInput.WriteLine("adb devices");

                var startCompute = false;
                var deviceNum    = 0;

                var row = "";

                while ((row = process.StandardOutput.ReadLine()) != null)
                {
                    if (startCompute)
                    {
                        if (String.IsNullOrWhiteSpace((row)))
                        {
                            break;
                        }

                        deviceNum++;
                        Console.WriteLine(String.Format("设备{0}:{1}", deviceNum, row));
                    }
                    if ("List of devices attached ".Equals(row))
                    {
                        startCompute = true;
                    }
                }
                return(deviceNum);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 获取像素大小
        /// </summary>
        /// <returns></returns>
        public static Tuple <int, int> GetCur()
        {
            using (Process process = CmdUtils.createCmd())
            {
                process.StandardInput.WriteLine("adb shell dumpsys window displays ");
                var row = "";

                while ((row = process.StandardOutput.ReadLine()) != null)
                {
                    if (row.Contains("cur="))
                    {
                        var items = row.Split(' ');
                        foreach (var item in items)
                        {
                            if (item.StartsWith("cur"))
                            {
                                var datas  = item.Substring(4).Split('x');
                                var width  = int.Parse(datas[0]);
                                var height = int.Parse(datas[1]);
                                return(new Tuple <int, int>(width, height));
                            }
                        }
                    }
                }

                return(null);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 获取事件空间大小
        /// </summary>
        /// <returns></returns>
        public static Tuple <int, int> GetEventWidthAndHeight()
        {
            using (Process process = CmdUtils.createCmd())
            {
                process.StandardInput.WriteLine("adb shell getevent -p");
                var row    = "";
                var width  = 0;
                var height = 0;
                while ((row = process.StandardOutput.ReadLine()) != null)
                {
                    if (row.Contains("0035") || row.Contains("0036"))
                    {
                        var items = row.Split(' ');
                        for (int i = 0, n = items.Length; i < n; i++)
                        {
                            if ("max".Equals(items[i]))
                            {
                                var value = items[i + 1];

                                if (row.Contains("0035"))
                                {
                                    width = int.Parse(value.Substring(0, value.Length - 1));
                                }
                                else
                                {
                                    height = int.Parse(value.Substring(0, value.Length - 1));
                                }
                            }
                        }

                        if (width != 0 && height != 0)
                        {
                            break;
                        }
                    }
                }

                return(new Tuple <int, int>(width, height));
            }
        }
Beispiel #4
0
        /// <summary>
        /// 获取屏幕点击像素点
        ///
        /// </summary>
        /// <param name="cur">像素空间</param>
        /// <param name="eventCur">事件空间</param>
        /// <returns></returns>
        public static Tuple <int, int> GetClickCurPoint(Tuple <int, int> cur, Tuple <int, int> eventCur)
        {
            int x = 0;
            int y = 0;

            using (Process getPintProcess = CmdUtils.createCmd())
            {
                getPintProcess.StandardInput.WriteLine("adb shell getevent");
                String line = null;

                while ((line = getPintProcess.StandardOutput.ReadLine()) != null)
                {
                    // /dev/input/event0: 0003 0035 00000341
                    // /dev/input/event0: 0003 0036 000008ec
                    if (line.Contains("0035"))
                    {
                        String[] items = line.Split(' ');
                        x = int.Parse(items[items.Length - 1], System.Globalization.NumberStyles.HexNumber);
                    }
                    else if (line.Contains("0036"))
                    {
                        String[] items = line.Split(' ');
                        y = int.Parse(items[items.Length - 1], System.Globalization.NumberStyles.HexNumber);
                    }

                    if (x != 0 && y != 0)
                    {
                        break;
                    }
                }
            }

            int curX = x * cur.Item1 / eventCur.Item1;
            int curY = y * cur.Item2 / eventCur.Item2;

            return(new Tuple <int, int>(curX, curY));
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            if (!envCheck())
            {
                return;
            }

            // 获取屏幕像素
            var cur = AdbUtils.GetCur();

            Console.WriteLine("屏幕像素:" + cur);

            // 获取事件空间大小
            var eventCur = AdbUtils.GetEventWidthAndHeight();

            Console.WriteLine("事件空间:" + eventCur);

            // 获取点击坐标点
            Console.WriteLine("请点击你想自动点击的位置:");
            var x = 0;
            var y = 0;

            using (Process getPintProcess = CmdUtils.createCmd())
            {
                getPintProcess.StandardInput.WriteLine("adb shell getevent");
                String line = null;

                var num = 0;
                while ((line = getPintProcess.StandardOutput.ReadLine()) != null && num < 3)
                {
                    // /dev/input/event0: 0003 0035 00000341
                    // /dev/input/event0: 0003 0036 000008ec
                    if (line.Contains("0035"))
                    {
                        var items = line.Split(' ');
                        x = int.Parse(items[items.Length - 1], System.Globalization.NumberStyles.HexNumber);
                        num++;
                        Console.WriteLine("第{0}次点击", num);
                    }
                    else if (line.Contains("0036"))
                    {
                        var items = line.Split(' ');
                        y = int.Parse(items[items.Length - 1], System.Globalization.NumberStyles.HexNumber);
                    }
                }
            }

            var curX = x * cur.Item1 / eventCur.Item1;
            var curY = y * cur.Item2 / eventCur.Item2;

            Console.WriteLine("最终点击像素点坐标,x:{0},y:{0}", curX, curY);



            Console.WriteLine("请输入点击的间隔时间(毫秒):");
            var intervel         = Console.ReadLine();
            var intervelMillions = int.Parse(intervel);

            Console.WriteLine("开始执行点击,如若需要结束程序前点击关闭或者输入q");
            using (var p = CmdUtils.createCmd())
            {
                AdbCronClicker.startClick(curX, curY, p, intervelMillions);

                // 点击点
                while (Console.ReadKey().Key != ConsoleKey.Q)
                {
                    // continue
                }
            }

            System.Environment.Exit(1);
        }
        public static void Main(string[] args)
        {
            //if (!envCheck())
            //{
            //    Console.ReadLine();
            //    return;
            //}

            // 获取屏幕像素
            var cur = AdbUtils.GetCur();

            Console.WriteLine("屏幕像素:" + cur);

            // 获取事件空间大小
            var eventCur = AdbUtils.GetEventWidthAndHeight();

            Console.WriteLine("事件空间:" + eventCur);

            Console.WriteLine("请进入四川人设小程序主页后输入回车:");
            Console.ReadLine();

            Console.WriteLine("请点击'四川人设系统窗口单位业务技能练兵比武网络答题竞赛活动':");
            var initPoint = AdbUtils.GetClickCurPoint(cur, eventCur);

            Console.WriteLine(initPoint);

            Console.WriteLine("请点击'答题检测'按钮");
            var answerCheck = AdbUtils.GetClickCurPoint(cur, eventCur);

            Console.WriteLine(answerCheck);

            Console.WriteLine("请点击'答题注意事项确认'按钮");
            var noticeConfirem = AdbUtils.GetClickCurPoint(cur, eventCur);

            Console.WriteLine(noticeConfirem);

            Console.WriteLine("请点击'答案选项A按钮,只能点击一个");
            var aAnswer = AdbUtils.GetClickCurPoint(cur, eventCur);

            Console.WriteLine(aAnswer);

            Console.WriteLine("请点击'答案选项D按钮,只能点击一个");
            var dAnswer = AdbUtils.GetClickCurPoint(cur, eventCur);

            Console.WriteLine(dAnswer);
            var answerHeight = (dAnswer.Item2 - aAnswer.Item2) / 3;

            Console.WriteLine("请点击'下一题'按钮");
            var newQuestion = AdbUtils.GetClickCurPoint(cur, eventCur);

            Console.WriteLine(newQuestion);

            Console.WriteLine("请点击'提交答卷'按钮");
            var submit = AdbUtils.GetClickCurPoint(cur, eventCur);

            Console.WriteLine(submit);

            Console.WriteLine("请点击'现在交卷'按钮");
            var submitNow = AdbUtils.GetClickCurPoint(cur, eventCur);

            Console.WriteLine(submitNow);

            Console.WriteLine("请点击左上角'返回'按钮");
            var returnNow = AdbUtils.GetClickCurPoint(cur, eventCur);

            Console.WriteLine(returnNow);

            Console.WriteLine("请输入点击的间隔时间(毫秒):");
            var intervelMillions = int.Parse(Console.ReadLine());

            Console.WriteLine("请输入想做的单选题数量:");
            var questionNum = int.Parse(Console.ReadLine());

            Console.WriteLine("请输入回车键从主页开始做题");
            Console.ReadLine();
            while (true)
            {
                using (var process = CmdUtils.createCmd())
                {
                    Console.WriteLine("开始做题......");
                    AdbUtils.click(process, initPoint);
                    Console.WriteLine(String.Format("已经点击'四川人设系统窗口单位业务技能练兵比武网络答题竞赛活动',point:{0}", initPoint));
                    Thread.Sleep(intervelMillions);

                    AdbUtils.click(process, answerCheck);
                    Console.WriteLine(String.Format("已经点击'答题检测'按钮,point:{0}", answerCheck));
                    Thread.Sleep(intervelMillions);

                    AdbUtils.click(process, noticeConfirem);
                    Console.WriteLine(String.Format("已经点击'答题注意事项确认'按钮,point:{0}", noticeConfirem));
                    Thread.Sleep(intervelMillions);

                    for (var i = 0; i < questionNum; i++)
                    {
                        // 防止答案位置变化,所以在那个x位置的y方向上多点几次
                        var x = aAnswer.Item1;
                        var y = aAnswer.Item2 - 2 * answerHeight;
                        for (int j = 0; j < 7; j++)
                        {
                            y += answerHeight;
                            var answer = new Tuple <int, int>(x, y);
                            AdbUtils.click(process, answer);
                            Console.WriteLine(String.Format("第{0}题,已经点击按钮,point:{1}", (i + 1), answer));
                            Thread.Sleep(2000);
                        }
                        // Thread.Sleep(intervelMillions);

                        AdbUtils.click(process, newQuestion);
                        Console.WriteLine(String.Format("已经点击'下一题'按钮,point:{0}", newQuestion));
                        Thread.Sleep(intervelMillions);
                    }



                    AdbUtils.click(process, submit);
                    Console.WriteLine(String.Format("已经点击'提交答卷'按钮',point:{0}", submit));
                    Thread.Sleep(intervelMillions);

                    AdbUtils.click(process, submitNow);
                    Console.WriteLine(String.Format("已经点击'现在交卷'按钮',point:{0}", submitNow));
                    Thread.Sleep(intervelMillions);

                    AdbUtils.click(process, returnNow);
                    Console.WriteLine(String.Format("已经点击'返回'按钮',point:{0}", returnNow));
                    Thread.Sleep(intervelMillions);


                    AdbUtils.click(process, submitNow);
                    Console.WriteLine(String.Format("已经点击'返回'按钮2',point:{0}", returnNow));
                    Thread.Sleep(intervelMillions);

                    // Console.WriteLine("请手工返回主页后输入回车键后继续做题");
                }
            }
        }