• 微信小程序挑一挑辅助


    1.窗体

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Drawing;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace 微信跳一跳辅助
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                int titleh = Height - ClientSize.Height;
                int titlew = Width - ClientSize.Width;
                Height = height + titleh;
                Width = width + titlew;

            }
            int time = int.Parse(System.Configuration.ConfigurationSettings.AppSettings["Time"]);//点击后截图时间;测试发现不能设太小
            string path = System.Configuration.ConfigurationSettings.AppSettings["AdbPath"];//adb.exe所在路径,徐包含adb.exe
            int height = int.Parse(System.Configuration.ConfigurationSettings.AppSettings["Height"]);//图片高度,一般截取第一张图后,打开图片用截图工具拖一下看看图片高度宽度各是多少
            int width =int.Parse(System.Configuration.ConfigurationSettings.AppSettings["Width"]);//图片宽度
            bool canCLick = false;
            Point Start;
            Point End;
            private void pictureBox1_Click(object sender, EventArgs e)

            {
                if (!canCLick)
                {
                    Text = Application.ProductName + "(不允许点击!)";
                    return;
                }
                var me = ((System.Windows.Forms.MouseEventArgs)(e));

                if (me.Button == MouseButtons.Left)//黑人位置
                {
                    Start = ((System.Windows.Forms.MouseEventArgs)(e)).Location;
                }
                else if (me.Button == MouseButtons.Right)//目标位置
                {
                    if(Start.Equals(new Point(0, 0)))
                    {
                        GetPhoneScreen();
                        Text = Application.ProductName + "(为你刷新手机屏幕)";
                        return;
                    }
                    End = ((System.Windows.Forms.MouseEventArgs)(e)).Location;
                    //计算两点直接的距离
                    //3.999022243950134这个值来自网络大神,本文思路也是按照网上别人给出的实例思路来的!
                    double value = Math.Sqrt(Math.Pow(Math.Abs(Start.X - End.X),2)+Math.Pow( Math.Abs(Start.Y - End.Y),2));
                   Text = Application.ProductName+ string.Format("(距离{0}需要时间:{1})", value, (3.999022243950134 * value).ToString("0"));
                  new ProcessDef(ProcessDefEnum.other)//此处引用本人自己写的,以前封装的类库,文后会贴ProcessDef源码,也可百度或者直接使用DotNet文章中的写法
                    {
                        FileName = path,
                        CommandText= string.Format("shell input swipe 100 100 200 200 {0}", (3.999022243950134 * value).ToString("0"))
                   }.RunGetResult();
                    canCLick = false;
                    Start = new Point(0, 0);
                    GetPhoneScreen();
                }
            }
            void GetPhoneScreen()
            {
                try
                {
                    if (File.Exists("D:tyt.png"))
                {
                    pictureBox1.Image = null;
                    Thread.Sleep(time);
                    GC.Collect();
                    File.Delete("D:tyt.png");
                }
                new ProcessDef(ProcessDefEnum.other)
                {
                    FileName = path,
                    CommandText = "shell /system/bin/screencap -p /sdcard/tyt.png"
                }.RunGetResult();
                Thread.Sleep(5);
                new ProcessDef(ProcessDefEnum.other)
                {
                    FileName = path,
                    CommandText = "pull /sdcard/tyt.png D:tyt.png"
                }.RunGetResult();
                pictureBox1.Image = new Bitmap("D:tyt.png");
                canCLick = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            private void Form1_Load(object sender, EventArgs e)
            {
                GetPhoneScreen();
            }       
        }

    }

    2.

            public class ProcessDef

            {
                public ProcessDef(ProcessDefEnum defEnum)
            {
                StartType = defEnum;
                switch (StartType)
                {
                    case ProcessDefEnum.cmd:

                        filename = "cmd.exe";
                        break;
                    case ProcessDefEnum.PwoerShell:

                        filename = "PowerShell.exe";
                        break;
                    default: break;
                }
                }
                public delegate void ResultHandler(string msg);
                public event ResultHandler OnResult;
                string filename = string.Empty;
                public string FileName
                {
                    get { return filename; }
                    set
                    {
                        switch (StartType)
                        {
                            case ProcessDefEnum.cmd:

                            filename = "cmd.exe";
                                break;
                            case ProcessDefEnum.PwoerShell:

                            filename = "PowerShell.exe";
                                break;
                            case ProcessDefEnum.other:
                                if (!string.IsNullOrEmpty(value))
                                {
                                filename = value;
                                }
                                break;
                        }
                    }
                }
                public string WorkDir { get; set; }
                public string CommandText { get; set; } = "echo .....";
                public bool UseShell { set { UseShell = value; } }
                public bool ShowConsole { get; set; } = false;
                public bool RedirectError { get; set; } = true;
                public bool RedirectInput { get; set; } = true;
                public bool RedirectdOutput { get; set; } = true;
                ProcessDefEnum StartType;
                string RuncmdOrPowerShell( bool rtn=false)
                {
                    ProcessStartInfo psi = new ProcessStartInfo()
                    {
                        FileName = FileName,
                        RedirectStandardError = RedirectError,
                        RedirectStandardInput = RedirectInput,
                        RedirectStandardOutput = RedirectdOutput,
                        CreateNoWindow = !ShowConsole,
                        UseShellExecute = false,
                    };
                    if (!string.IsNullOrEmpty(WorkDir) && Directory.Exists(WorkDir))
                    {
                        psi.WorkingDirectory = WorkDir;

                    }
                    Process process = new Process()
                    {
                        StartInfo = psi
                    };
                    process.Start();
                    process.StandardInput.WriteLine(CommandText);
                    process.StandardInput.WriteLine ("exit");
                    process.StandardInput.AutoFlush = true;
                if (rtn)
                {
                    return process.StandardOutput.ReadToEnd();
                }
                else
                {
                    while (!process.StandardOutput.EndOfStream)
                    {
                        string msg = process.StandardOutput.ReadLine();
                        if (!string.IsNullOrEmpty(msg))
                            OnResult?.Invoke(msg);
                    }
                    return "";
                }
                   // process.WaitForExit();
                }
                string RunOther(bool rtn = false)
            {
                ProcessStartInfo psi = new ProcessStartInfo()
                {
                    FileName = FileName,
                    RedirectStandardError = RedirectError,
                    RedirectStandardInput = RedirectInput,
                    RedirectStandardOutput = RedirectdOutput,
                    CreateNoWindow = !ShowConsole,
                    UseShellExecute = false,
                    Arguments = CommandText,
                };

                if (!string.IsNullOrEmpty(WorkDir) && Directory.Exists(WorkDir))
                {
                    psi.WorkingDirectory = WorkDir;

                }
                Process process = new Process()
                {
                    StartInfo = psi
                };
                process.Start();
                if (rtn)
                {
                    return process.StandardOutput.ReadToEnd();
                }
                else
                {
                    OnResult?.Invoke(filename + " " + CommandText);
                    while (!process.StandardOutput.EndOfStream)
                    {
                        string msg = process.StandardOutput.ReadLine();
                        if (!string.IsNullOrEmpty(msg))
                            OnResult?.Invoke(msg);
                    }
                    return "";
                }
            }
                public void Run()
                {
                switch (StartType)
                {
                    case ProcessDefEnum.cmd:
                    case ProcessDefEnum.PwoerShell:
                        RuncmdOrPowerShell();
                        break;
                    case ProcessDefEnum.other:
                        RunOther();
                        break;
                    default:break;
                }
                }
                public string RunGetResult()
            {
                string result = string.Empty;
                switch (StartType)
                {
                    case ProcessDefEnum.cmd:
                    case ProcessDefEnum.PwoerShell:
                      result=  RuncmdOrPowerShell();
                        break;
                    case ProcessDefEnum.other:
                       result= RunOther();
                        break;
                    default:break;
                }
                return result;
            }
           
        }
        public enum ProcessDefEnum
        {
            cmd = 1,
            PwoerShell = 2,
            other = 3
        }

    3.Program

    namespace 微信跳一跳辅助
    {
        static class Program
        {
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
        }
    }

    4.App.config

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <startup> 
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
        </startup>
      <appSettings>
        <add key="AdbPath" value="D: oolsAdbadb.exe"/>
        <add key="Time" value="700"/>
        <add key="Height" value="620"/>
        <add key ="Width" value="375"/>
      </appSettings>
    </configuration>

    本文调用adb的程序不建议用文中贴出的类,本人用是因为有封装的Dll直接调用RunGetResult()即可:

    给大家搜一个:

    建议使用(以下形式)以下代码来自于http://blog.csdn.net/feifei_csdn/article/details/53455490:

    1. System.Diagnostics.Process p = new System.Diagnostics.Process();  
    2.             p.StartInfo.UseShellExecute = false;  
    3.             p.StartInfo.CreateNoWindow = true;  
    4.             p.StartInfo.FileName = "cmd.exe";  
    5.             p.StartInfo.Arguments = "/c adb shell cat /proc/gesture_state";  
    6.             p.StartInfo.RedirectStandardError = true;  
    7.             p.StartInfo.RedirectStandardInput = true;  
    8.             p.StartInfo.RedirectStandardOutput = true;  
    9.                 
    10.             p.Start();  
    11.   
    12.             string outtr = p.StandardOutput.ReadToEnd();  
    13.             MessageBox.Show(outtr);  
    14.             p.Close();  
  • 相关阅读:
    Java Leetcode 两数之和
    Springboot 实现前后分离的固定响应结构 {code,data,msg} 代码及想法
    Java 通过原子类 AtomicStampedReference 实现自旋锁
    【待整理】PC端
    【Python】自动发送邮件
    【Python】调用C/C++ SDK/SO动态库
    【Python】整个项目所需的依赖包列表打包/项目迁移
    【待整理】工具
    【数据库】+Navicat 过期/14天试用期满
    【待整理】【后端】
  • 原文地址:https://www.cnblogs.com/zzp0320/p/8288445.html
Copyright © 2020-2023  润新知