微信小程序挑一挑輔助

1.窗體shell

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;xcode

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));app

            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.spa

        public class ProcessDef.net

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

                    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:\tools\Adb\adb.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();  
相關文章
相關標籤/搜索