我目前有一个应用程序正在使用ADB向我的手机发送点按输入我正在寻找一种更快速发送它们的方法。现在我可以发送一个大约每.750秒的点击,我想通过类似的很多。目前的问题是,如果我大概.600左右手机开始冻结,所以我想知道是否有办法更有效地发送水龙头。
class Program
{
static bool run = true;
static bool wait = false;
static int Xr = 480;
static int Yr = 800;
static int Rx = 0;
static int Ry = 0;
static int tapRate = 600;
static string ADBLocation = @"C:\Users\PATH\Downloads\ADB";
static void Main(string[] args)
{
Console.WriteLine("Getting Resolution...");
setResolution();
Console.WriteLine("Resolution set to X: {0} Y: {1}",Rx,Ry);
Console.WriteLine("Press Enter to Continue...");
Console.WriteLine("Please set a Tap rate (Milliseconds)");
tapRate = Convert.ToInt32(Console.ReadLine());
Console.ReadKey();
Thread th = new Thread(thread);
th.Start();
while (run)
{
Console.WriteLine("Stop Clicking?");
Console.WriteLine("1. Stop");
Console.WriteLine("2. Pause");
Console.WriteLine("3. Video");
switch (Console.ReadLine())
{
case "1":
run = false;
break;
case "2":
wait = true;
Console.WriteLine("Press anything to Continue");
Console.ReadKey();
wait = false;
break;
case "3":
wait = true;
video();
wait = false;
break;
case "4":
wait = true;
getScreenCap();
wait = false;
break;
default:
break;
}
}
}
public static int getX(int X)
{
return (int)(((double)X / (double)Xr) * (double)Rx);
}
public static int getY(int Y)
{
return (int)(((double)Y / (double)Yr) * (double)Ry);
}
public static void anilizeImage()
{
System.Threading.Thread.Sleep(10000);
using (Image d = Image.FromFile(string.Format("{0}\\screencap.png", ADBLocation)))
{
d.Save(string.Format("{0}\\screencap.bmp", ADBLocation), ImageFormat.Bmp);
using (Bitmap bmp = new Bitmap(string.Format("{0}\\screencap.bmp", ADBLocation)))
{
Color[] color = new Color[5];
color[0] = bmp.GetPixel(getX(250), getY(500));
color[1] = bmp.GetPixel(getX(250), getY(505));
color[2] = bmp.GetPixel(getX(250), getY(495));
color[3] = bmp.GetPixel(getX(255), getY(500));
color[4] = bmp.GetPixel(getX(245), getY(500));
Color item = color[0];
{
if (item.R != 80)
return;
if (item.B != 80)
return;
if (item.G != 80)
return;
}
item = color[1];
{
if (item.R != 80)
return;
if (item.B != 80)
return;
if (item.G != 80)
return;
}
item = color[2];
{
if (item.R != 80)
return;
if (item.B != 80)
return;
if (item.G != 80)
return;
}
item = color[3];
{
if (item.R != 8)
return;
if (item.B != 147)
return;
if (item.G != 127)
return;
}
item = color[4];
{
if (item.R != 80)
return;
if (item.B != 80)
return;
if (item.G != 80)
return;
}
wait = true;
video();
wait = false;
}
}
}
public static void setResolution()
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = string.Format(@"/c {0}\adb.exe shell screencap -p /sdcard/screencap.png",ADBLocation);
process.StartInfo = startInfo;
process.Start();
System.Threading.Thread.Sleep(4000);
startInfo.Arguments = string.Format(@"/c {0}\adb.exe pull /sdcard/screencap.png {0}", ADBLocation);
process.StartInfo = startInfo;
process.Start();
System.Threading.Thread.Sleep(2000);
startInfo.Arguments = string.Format(@"/c {0}\adb.exe shell rm -r /sdcard/screencap.png", ADBLocation);
process.StartInfo = startInfo;
process.Start();
System.Threading.Thread.Sleep(3000);
using (Image d = Image.FromFile(string.Format("{0}\\screencap.png", ADBLocation)))
{
Ry=d.Height;
Rx = d.Width;
}
}
public static void getScreenCap()
{
try
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = string.Format(@"/c {0}\adb.exe shell screencap -p /sdcard/screencap.png", ADBLocation);
process.StartInfo = startInfo;
process.Start();
System.Threading.Thread.Sleep(4000);
startInfo.Arguments = string.Format(@"/c {0}\adb.exe pull /sdcard/screencap.png {0}", ADBLocation);
process.StartInfo = startInfo;
process.Start();
System.Threading.Thread.Sleep(2000);
startInfo.Arguments = string.Format(@"/c {0}\adb.exe shell rm -r /sdcard/screencap.png", ADBLocation);
process.StartInfo = startInfo;
process.Start();
System.Threading.Thread.Sleep(3000);
anilizeImage();
File.Delete(string.Format("{0}\\screencap.png", ADBLocation));
File.Delete(string.Format("{0}\\screencap.bmp", ADBLocation));
}
catch
{
if (File.Exists(string.Format("{0}\\screencap.png", ADBLocation)))
File.Delete(string.Format("{0}\\screencap.png", ADBLocation));
if (File.Exists(string.Format("{0}\\screencap.bmp", ADBLocation)))
File.Delete(string.Format("{0}\\screencap.bmp", ADBLocation));
}
}
public static void uplock()
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = @"/c C:\Users\PATH\Downloads\ADB\adb.exe shell input keyevent 26";
process.StartInfo = startInfo;
process.Start();
System.Threading.Thread.Sleep(1000);
startInfo.Arguments = @"/c C:\Users\PATH\Downloads\ADB\adb.exe shell input swipe 300 500 300 150";
process.StartInfo = startInfo;
process.Start();
}
public static void video()
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = string.Format(@"/c {2}\adb.exe shell input tap {0} {1}",getX(300),getY(500),ADBLocation);
process.StartInfo = startInfo;
process.Start();
process.Start();
Console.WriteLine("Clicked Video Button");
Console.WriteLine("Waiting 45 seconds");
System.Threading.Thread.Sleep(45000);
startInfo.Arguments = string.Format(@"/c {0}\adb.exe shell input keyevent 4", ADBLocation);
process.StartInfo = startInfo;
process.Start();
Console.WriteLine("Back Button Clicked");
Console.WriteLine("Waiting 10 seconds");
System.Threading.Thread.Sleep(10000);
startInfo.Arguments = string.Format(@"/c {0}\adb.exe shell input keyevent 4",ADBLocation);
process.StartInfo = startInfo;
process.Start();
Console.WriteLine("Back Button Clicked");
Console.WriteLine("Waiting 2 seconds");
System.Threading.Thread.Sleep(2000);
startInfo.Arguments = string.Format(@"/c {2}\adb.exe shell input tap {0} {1}",getX(250),getY(500),ADBLocation);
process.StartInfo = startInfo;
process.Start();
}
public static void thread()
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = string.Format(@"/c {2}\adb.exe shell input tap {0} {1}",getX(250), getY(120),ADBLocation);
process.StartInfo = startInfo;
DateTime shadow = new DateTime();
DateTime screencap = DateTime.Now;
while(run)
{
while (wait)
{
System.Threading.Thread.Sleep(50);
}
System.Threading.Thread.Sleep(tapRate);
//Console.WriteLine("{0} launched", i);
if (screencap.AddMinutes(2) < DateTime.Now)
{
Thread cap = new Thread(getScreenCap);
cap.Start();
screencap = DateTime.Now;
}
if (shadow == new DateTime() || shadow.AddMinutes(10) < DateTime.Now)
{
startInfo.Arguments = string.Format(@"/c {2}\adb.exe shell input tap {0} {1}", getX(140), getY(680), ADBLocation);
shadow = DateTime.Now;
}
else
{
startInfo.Arguments = string.Format(@"/c {2}\adb.exe shell input tap {0} {1}", getX(250), getY(120), ADBLocation);
}
process.StartInfo = startInfo;
process.Start();
}
}
}