通过adb实现拖拽

//        public static void drag(string sn, string devicename, int x1, int y1, int x2, int y2, int step = 10)
//        {
//            try
//            {
//                bool exitflag = false;

//                Process pp = new Process();
//                pp.StartInfo = new ProcessStartInfo();
//                pp.StartInfo.FileName = "adb.exe";
//                pp.StartInfo.Arguments = " -s " + sn + " shell ";
//                pp.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
//                pp.StartInfo.CreateNoWindow = true;
//                pp.StartInfo.WorkingDirectory = Application.StartupPath;
//                pp.StartInfo.UseShellExecute = false;
//                pp.StartInfo.RedirectStandardInput = true;
//                pp.StartInfo.RedirectStandardOutput = true;
//                pp.StartInfo.RedirectStandardError = true;

//                DataReceivedEventHandler dataReceivedEventHandler = new DataReceivedEventHandler((sender, e) =>
//                {
//                    if (null == e.Data) return;
//                });

//                pp.ErrorDataReceived += dataReceivedEventHandler;
//                pp.OutputDataReceived += dataReceivedEventHandler;

//                pp.EnableRaisingEvents = true;
//                pp.Exited += new EventHandler((sender, e) =>
//                {
//                    exitflag = true;
//                });

//                pp.Start();
//                pp.BeginOutputReadLine();
//                pp.BeginErrorReadLine();

//                int rc = 30;
//                do
//                {
//                    Thread.Sleep(500);

//                    if (30 == rc)
//                    {
//                        string tips = "";

//                        int dir = 0;

//                        List<int> lstX = new List<int>();
//                        if (x2 > x1) // 向右
//                        {
//                            dir = 1;

//                            for (int x = x1; x < x2; x += Math.Abs(x2 - x1) / step)
//                            {
//                                lstX.Add(x);
//                            }

//                            lstX.Add(x2);
//                        }
//                        else if (x2 < x1) // 向左
//                        {
//                            dir = 2;
//                            for (int x = x2; x > x1; x -= Math.Abs(x2 - x1) / step)
//                            {
//                                lstX.Add(x);
//                            }

//                            lstX.Add(x1);
//                        }
//                        else
//                        {
//                            lstX.Add(x1);
//                        }

//                        List<int> lstY = new List<int>();
//                        if (y2 > y1) // 向下
//                        {
//                            dir = 3;
//                            for (int y = y1; y < y2; y += Math.Abs(y2 - y1) / step)
//                            {
//                                lstY.Add(y);
//                            }

//                            lstY.Add(y2);
//                        }
//                        else if (y2 < y1) // 向上
//                        {
//                            dir = 4;
//                            for (int y = y2; y > y1; y -= Math.Abs(y2 - y1) / step)
//                            {
//                                lstY.Add(y);
//                            }

//                            lstY.Add(y1);
//                        }
//                        else
//                        {
//                            lstY.Add(y1);
//                        }

//                        if (1 == dir || 2 == dir) // 左 右  x发生变化 y发生波动
//                        {
//                            for (int i = 0; i < lstX.Count; ++i)
//                            {
//                                tips += @" sendevent {inputname} 3  53      {x}       
// sendevent {inputname} 3  54      {y}       
// sendevent {inputname} 0  0       0
//".Replace("{inputname}", devicename)
//    .Replace("{x}", lstX[i].ToString())
//    .Replace("{y}", lstY[new Random(DateTime.Now.Second).Next(0, lstY.Count)].ToString());
//                            }
//                        }

//                        if (3 == dir || 4 == dir) // 上 下 y发生变化 x发生波动
//                        {
//                            for (int i = 0; i < lstY.Count; ++i)
//                            {
//                                tips += @" sendevent {inputname} 3  53      {x}       
// sendevent {inputname} 3  54      {y}       
// sendevent {inputname} 0  0       0
//".Replace("{inputname}", devicename)
//    .Replace("{x}", lstX[new Random(DateTime.Now.Second).Next(0, lstX.Count)].ToString())
//    .Replace("{y}", lstY[i].ToString());
//                            }
//                        }


//                        string tip = @" sendevent {inputname} 3  57      0         
// sendevent {inputname} 3  53      {x1}       
// sendevent {inputname} 3  54      {y1}       
// sendevent {inputname} 0  0       0 
// sendevent {inputname} 1  330     1         
// sendevent {inputname} 3  53      {x1}       
// sendevent {inputname} 3  54      {y1}       
// sendevent {inputname} 0  0       0      
//{tips}sendevent {inputname} 3  57      4294967295
// sendevent {inputname} 1  330     0         
// sendevent {inputname} 0  0       0         
//exit
//".Replace("{inputname}", devicename).Replace("{x1}", x1.ToString()).Replace("{y1}", y1.ToString()).Replace("{x2}", x2.ToString()).Replace("{y2}", y2.ToString()).Replace("{tips}", tips);

//                        pp.StandardInput.Write(tip);
//                    }
//                }
//                while (!exitflag && --rc > 0 && !pp.WaitForExit(500));
//            }
//            catch (Exception err)
//            {
//                Program.LogWarn(err, "drag");
//            }
//        }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值