200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > 50行代码完成微信小程序-跳一跳辅助工具 让你成为朋友圈最靓的仔

50行代码完成微信小程序-跳一跳辅助工具 让你成为朋友圈最靓的仔

时间:2019-08-25 13:18:39

相关推荐

50行代码完成微信小程序-跳一跳辅助工具 让你成为朋友圈最靓的仔

前言

12月28日,微信更新的 6.6.1 版本开放了小游戏,微信启动页面还重点推荐了小游戏「跳一跳」。

不说废话直接上代码

设置公共参数

double ratio = 1;//弹跳系数,用于屏幕距离转换为左键按下时长double jumpRange = 100; //跳跃范围bool leftDowned = false; //左键是否按下DateTime leftDownTime = DateTime.Now; //记录鼠标左键按下时时间Point lastlocationpoint = new Point(0, 0);//上一次位置

导入系统Dll , 模拟鼠标左键按下抬起

[System.Runtime.InteropServices.DllImport("user32")]private static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);const int MOUSEEVENTF_LEFTDOWN = 0x0002; //模拟鼠标左键按下 const int MOUSEEVENTF_LEFTUP = 0x0004;//模拟鼠标左键抬起

创建一个定时器

Timer timer = new Timer();private void Form7_Load(object sender, EventArgs e){timer.Start();timer.Interval = 5;//时间间隔5毫秒,^_^ 大胆点不要觉得太快了, CPU忙不过来timer.Tick += Timer_Tick;}private void Timer_Tick(object sender, EventArgs e){if (Control.ModifierKeys == Keys.Control){Point npoint = Control.MousePosition;double distance = Math.Sqrt((npoint.X - lastlocationpoint.X) * (npoint.X - lastlocationpoint.X) + (npoint.Y - lastlocationpoint.Y) * (npoint.Y - lastlocationpoint.Y));double.TryParse(textBox2.Text, out ratio);if (distance > 0){jumpRange = distance * ratio;textBox1.AppendText("当前位置:(" + npoint.X + "," + npoint.Y + "), 上次位置:(" + lastlocationpoint.X + "," + lastlocationpoint.Y + ");");textBox1.AppendText("距离:" + distance + ";\r\n");}lastlocationpoint = Control.MousePosition;}if (Control.ModifierKeys == Keys.Shift && jumpRange > 0){if (!leftDowned){mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);leftDownTime = DateTime.Now;leftDowned = true;}else{if (DateTime.Now.Subtract(leftDownTime).TotalMilliseconds > jumpRange){textBox1.AppendText("跳跃距离:" + jumpRange + "\r\n");leftDowned = false;mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);jumpRange = 0;}}}}

按住Ctrl键记录两次中心点然后长按Shift完成跳跃通过调整弹跳系数调整远近在输出框中可查看距离全程不需要点击鼠标

上效果

围观成绩

需要全部源码的可以给我留言

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。