Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将点击输入更快地发送到我的Android手机_C#_Android - Fatal编程技术网

C# 将点击输入更快地发送到我的Android手机

C# 将点击输入更快地发送到我的Android手机,c#,android,C#,Android,我目前有一个应用程序正在使用ADB向我的手机发送点击输入,我正在寻找一种更快发送的方法。现在我大约每0.750秒就可以发送一次信号,我希望能提高很多。目前的问题是,如果我经常使用.600,手机就会开始冻结,所以我想知道是否有办法更有效地发送信号 class Program { static bool run = true; static bool wait = false; static int Xr = 480; static int Yr = 800;

我目前有一个应用程序正在使用ADB向我的手机发送点击输入,我正在寻找一种更快发送的方法。现在我大约每0.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();

        }
    }
}
类程序
{
静态布尔运行=真;
静态布尔等待=假;
静态int Xr=480;
静态int-Yr=800;
静态int Rx=0;
静态int-Ry=0;
静态int tapRate=600;
静态字符串ADBLocation=@“C:\Users\PATH\Downloads\ADB”;
静态void Main(字符串[]参数)
{
Console.WriteLine(“获得解决方案…”);
setResolution();
WriteLine(“分辨率设置为X:{0}Y:{1}”,Rx,Ry);
Console.WriteLine(“按Enter键继续…”);
Console.WriteLine(“请设置点击率(毫秒)”);
tapRate=Convert.ToInt32(Console.ReadLine());
Console.ReadKey();
螺纹th=新螺纹(螺纹);
th.Start();
while(运行)
{
Console.WriteLine(“停止单击?”);
控制台。写入线(“1.停止”);
控制台。写线(“2。暂停”);
Console.WriteLine(“3.视频”);
开关(Console.ReadLine())
{
案例“1”:
运行=错误;
打破
案例“2”:
等待=真;
Console.WriteLine(“按任何键继续”);
Console.ReadKey();
等待=错误;
打破
案例“3”:
等待=真;
视频();
等待=错误;
打破
案例“4”:
等待=真;
getScreenCap();
等待=错误;
打破
违约:
打破
}
}
}
公共静态intgetx(intx)
{
返回(int)(((双)X/(双)Xr)*(双)Rx);
}
公共静态整型(整型)
{
报税表(整数)(((双)年/(双)年)*(双)年);
}
公共静态无效anilizeImage()
{
系统线程线程睡眠(10000);
使用(Image d=Image.FromFile(string.Format(“{0}\\screencap.png”,ADBLocation)))
{
d、 保存(string.Format(“{0}\\screencap.bmp”,ADBLocation),ImageFormat.bmp);
使用(位图bmp=新位图(string.Format(“{0}\\screencap.bmp”,ADBLocation)))
{
颜色[]颜色=新颜色[5];
颜色[0]=bmp.GetPixel(getX(250),getY(500));
color[1]=bmp.GetPixel(getX(250),getY(505));
颜色[2]=bmp.GetPixel(getX(250),getY(495));
颜色[3]=bmp.GetPixel(getX(255),getY(500));
color[4]=bmp.GetPixel(getX(245),getY(500));
颜色项=颜色[0];
{
如果(项目R!=80)
返回;
如果(项目B!=80)
返回;
如果(项目G!=80)
返回;
}
项目=颜色[1];
{
如果(项目R!=80)
返回;
如果(项目B!=80)
返回;
如果(项目G!=80)
返回;
}
项目=颜色[2];
{
如果(项目R!=80)
返回;
如果(项目B!=80)
返回;
如果(项目G!=80)
返回;
}
项目=颜色[3];
{
如果(项目R!=8)
返回;
如果(项目B!=147)
返回;
如果(项目G!=127)
返回;
}
项目=颜色[4];
{
如果(项目R!=80)
返回;
如果(项目B!=80)
返回;
如果(项目G!=80)
返回;
}
等待=真;
视频();
等待=错误;
}
}
}
公共静态无效集合解析()
{
System.Diagnostics.Process Process=新的System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo=新系统.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();
系统线程线程睡眠(4000);
startInfo.Arguments=string.Format(@/c{0}\adb.exe pull/sdcard/screencap.png{0}),ADBLocation);
process.StartInfo=StartInfo;
process.Start();
系统线程线程睡眠(2000);
startInfo.Arguments=string.Format(@“/c{0}\adb.exe shell rm-r/sdcard/screencap.png”,ADBLocation);
process.StartInfo=StartInfo;
process.Start();
系统线程线程睡眠(3000);
使用(Image d=Image.FromFile(string.Format(“{0}\\screencap.png”,ADBLocation)))
{
Ry=d.高度;
Rx=d.宽度;
}
}
公共静态void getScreenCap()
{
尝试
{
System.Diagnostics.Process Process=新的System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo=新系统.Diagnostics.ProcessStartInfo()