农场工具程序设计(三)

首先声明:本人设计和开发这个程序没有任何商业目的,完全是用于学习交流!程序的主要设计思路为模拟鼠标操作,没有截取任何商业信息,无病毒、无木马!没有损害他人利益,只是一个替代用户手工操作的工具!使用者也请勿用用于商业用途以及损害他人利益之用!在使用过程中,如腾讯公司警告你不能使用此工具,请暂停使用!谢谢合作!

9、定时为自己摘取

添加一个计时器,设定果实成熟时间,当时间一到就为自己摘取果实,其需要添加的控件如下图所示:

为计时器添加如下代码:

private void myTimer_Tick(object sender, EventArgs e)

{

DateTime timeNow = DateTime.Now;

TimeSpan leavingTime;

leavingTime = MyGetTime.Subtract(timeNow);

leavingTimeLabelX.Text = "剩下时间:" + leavingTime.Hours.ToString("00") + ":"

+ leavingTime.Minutes.ToString("00") + ":" + leavingTime.Seconds.ToString("00");

if (leavingTime.Seconds < 0)

{

myTimer.Enabled = false;

GetMyFarm();

}

}

同时,为“设置为自己收取时间”按钮添加如下代码:

private void 设置为自己收取时间_Click(object sender, EventArgs e)

{

if (MyGetTime.Second != 0)

{

DialogResult dialogResult;

dialogResult = MessageBox.Show("时间已经设置!是否重新设置?", "提示", MessageBoxButtons.YesNo);

if (dialogResult == DialogResult.Yes)

{

double hours = double.Parse(hourTextBox.Text);

double minutes = double.Parse(minuterTextBox.Text);

double seconds = double.Parse(secondTextBox.Text);

MyGetTime = DateTime.Now.AddHours(hours).AddMinutes(minutes).AddSeconds(seconds);

myTimer.Enabled = true;

}

}

else

{

double hours = double.Parse(hourTextBox.Text);

double minutes = double.Parse(minuterTextBox.Text);

double seconds = double.Parse(secondTextBox.Text);

MyGetTime = DateTime.Now.AddHours(hours).AddMinutes(minutes).AddSeconds(seconds);

myTimer.Enabled = true;

}

}

10、模拟鼠标事件

模拟鼠标事件主要通过编写一个文本来实现对鼠标事件的模拟,该文本文件的内容格式为“光标X坐标,光标Y坐标,鼠标事件,事件暂停时间”,其中鼠标事件如果为单击则值为1,如果为双击则值为2,例如“1016,702,1,500”表示在坐标(1016,702)处单击鼠标,然后暂停0.5秒。

首先定义一个光标事件类,如下:

private class RecordCursorEvent //记录光标事件

{

public int CursorX;//光标的X位置

public int CursorY;//光标的Y位置

public int sleepTime;//两个操作之间的间隔时间

public int mouseEvent;//鼠标事件,1表示单击,2表示双击

}

然后在全局变量中定义一个动态数组变量来保存光标事件,如下:

private ArrayList CursorArrayList;//用一个动态数组保存光标事件ecordCursorEvent

定义一个读取坐标文件的函数ReadInputData,其代码如下:

private void ReadInputData(string filePath)

{

CursorArrayList = new ArrayList();

StreamReader sr = new StreamReader(filePath);

RecordCursorEvent tempCursorEvent01=new RecordCursorEvent();

String line;

int i;

line = sr.ReadLine();//读取文本的第一行

i = line.IndexOf(char.ConvertFromUtf32(44));//寻找逗号

tempCursorEvent01.CursorX = int.Parse(Microsoft.VisualBasic.Strings.Left(line, i));

line = Microsoft.VisualBasic.Strings.Right(line, line.Length - i - 1);

i = line.IndexOf(char.ConvertFromUtf32(44));//寻找逗号

tempCursorEvent01.CursorY = int.Parse(Microsoft.VisualBasic.Strings.Left(line, i));

line = Microsoft.VisualBasic.Strings.Right(line, line.Length - i - 1);

i = line.IndexOf(char.ConvertFromUtf32(44));//寻找逗号

tempCursorEvent01.mouseEvent = int.Parse(Microsoft.VisualBasic.Strings.Left(line, i));

tempCursorEvent01.sleepTime = int.Parse(Microsoft.VisualBasic.Strings.Right(line, line.Length - i - 1));

CursorArrayList.Add(tempCursorEvent01);

while ((line = sr.ReadLine()) != null)

{

RecordCursorEvent tempCursorEvent = new RecordCursorEvent();

i = line.IndexOf(char.ConvertFromUtf32(44));//寻找逗号

tempCursorEvent.CursorX = int.Parse(Microsoft.VisualBasic.Strings.Left(line, i));

line = Microsoft.VisualBasic.Strings.Right(line, line.Length - i - 1);

i = line.IndexOf(char.ConvertFromUtf32(44));//寻找逗号

tempCursorEvent.CursorY = int.Parse(Microsoft.VisualBasic.Strings.Left(line, i));

line = Microsoft.VisualBasic.Strings.Right(line, line.Length - i - 1);

i = line.IndexOf(char.ConvertFromUtf32(44));//寻找逗号

tempCursorEvent.mouseEvent = int.Parse(Microsoft.VisualBasic.Strings.Left(line, i));

tempCursorEvent.sleepTime = int.Parse(Microsoft.VisualBasic.Strings.Right(line, line.Length - i - 1));

CursorArrayList.Add(tempCursorEvent);

}

}

添加一个按钮,设置其NameText属性都为“打开坐标设定文件”,为其Click事件添加如下代码:

private void 设置自动打开_Click(object sender, EventArgs e)

{

//打开坐标文件

OpenFileDialog openDG = new OpenFileDialog();

openDG.Title = "打开坐标数据文本";

openDG.Filter = "文本文件(*.txt)|*.txt|DAT文件(*.dat)|*.dat";

openDG.ShowDialog();

string filePath;

filePath = openDG.FileName;

if (filePath == "")

{

MessageBox.Show("选择文件路径错误!");

}

else

{

ReadInputData(filePath);

}

}

然后添加一个按钮,设置其NameText属性都为“模拟鼠标事件”,为其Click事件添加如下代码:

private void 模拟鼠标事件_Click(object sender, EventArgs e)

{

//首先回到桌面

keybd_event((byte)Keys.RWin, 0, 0, 0);

keybd_event(68, 0, 0, 0);

keybd_event((byte)Keys.RWin, 0, 0x2, 0);

keybd_event(68, 0, 0x2, 0);

System.Threading.Thread.Sleep(1000);

for (int i = 0; i < CursorArrayList.Count; i++)

{

RecordCursorEvent tempCursorEvent = (RecordCursorEvent)CursorArrayList[i];

int x, y;

x = tempCursorEvent.CursorX; y = tempCursorEvent.CursorY;

if (tempCursorEvent.mouseEvent == 1)

{

OnClickEvent(x, y);

}

else if (tempCursorEvent.mouseEvent == 2)

{

DoubleClickEvent(x, y);

}

System.Threading.Thread.Sleep(tempCursorEvent.sleepTime);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值