农场工具程序设计(三)
来源:互联网 发布:赋码软件 编辑:程序博客网 时间:2024/06/11 12:35
首先声明:本人设计和开发这个程序没有任何商业目的,完全是用于学习交流!程序的主要设计思路为模拟鼠标操作,没有截取任何商业信息,无病毒、无木马!没有损害他人利益,只是一个替代用户手工操作的工具!使用者也请勿用用于商业用途以及损害他人利益之用!在使用过程中,如腾讯公司警告你不能使用此工具,请暂停使用!谢谢合作!
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);
}
}
添加一个按钮,设置其Name和Text属性都为“打开坐标设定文件”,为其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);
}
}
然后添加一个按钮,设置其Name和Text属性都为“模拟鼠标事件”,为其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);
}
}
- 农场工具程序设计(三)
- 农场工具程序设计(一)
- 农场工具程序设计(二)
- 汇编语言程序设计(三)
- Windows程序设计(三)
- 指针程序设计(三)
- shell程序设计(三)
- 程序结构&&程序设计(三)
- windows程序设计(三)
- Flex制作人人开心农场工具
- 三、简单程序设计(顺序结构程序设计)
- 标准C程序设计(三)
- Python程序设计(三)选择
- 汇编语言程序设计读书笔记(1)- 相关工具
- QQ农场破解思路(版本20091212)
- JavaScript高级程序设计(读书笔记)(三)
- 《Windows 程序设计》学习笔记(三)
- Java基本的程序设计结构(三)
- 如何在编程中节约系统内存
- Jaxp---characters(char[] ch, int start, int length)
- 编程实现关闭电脑显示器
- 农场工具程序设计(一)
- 农场工具程序设计(二)
- 农场工具程序设计(三)
- 局域网控制(一)界面传输
- 局域网控制(二)——控制客户端
- pku 1166[回溯]
- 局域网控制(三)——远程关机重启等
- sfdfe
- 投影纹理映射(Projective Texture Mapping)
- 局域网控制下载地址
- 基于Visual C#的Windows API 程序设计——控制你的Windows系统