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

前言

2017年12月28日,微信更新的 6.6.1 版本开放了小游戏,微信启动页面还重点推荐了小游戏「跳一跳」。
在这里插入图片描述

不说废话直接上代码

  1. 设置公共参数
	double ratio = 1;	//弹跳系数,用于屏幕距离转换为左键按下时长
	double jumpRange = 100;    //跳跃范围
	bool leftDowned = false;    //左键是否按下
	DateTime leftDownTime = DateTime.Now; //记录鼠标左键按下时时间
	Point lastlocationpoint = new Point(0, 0);//上一次位置
  1. 导入系统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;//模拟鼠标左键抬起 
 
  1. 创建一个定时器
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完成跳跃
  • 通过调整弹跳系数调整远近
  • 在输出框中可查看距离
  • 全程不需要点击鼠标

上效果

在这里插入图片描述

围观成绩

在这里插入图片描述
需要全部源码的可以给我留言

猜你喜欢

转载自blog.csdn.net/daengwei/article/details/123104821