创建python项目jump_weixin,新建python程序jump.py
需要4个辅助文件【adb.exe,AdbWinApi.dll,AdbWinUsbApi.dll,fastboot.exe】,放到项目根目录
辅助文件下载地址:链接:https://pan.baidu.com/s/1sljznFR 密码:gzeg
目录结构如下:
编辑jump.py:
import os import numpy import matplotlib.pyplot as plt import PIL from matplotlib.animation import FuncAnimation import time need_update = True # 获取截图 def get_screen_image(): os.system('adb shell screencap -p /sdcard/screen.png') # 截取手机屏幕 os.system('adb pull /sdcard/screen.png') # 把手机上的截图拿到电脑上 return numpy.array(PIL.Image.open('screen.png')) def jump_to_next(point1, point2): # 执行跳的操作 x1, y1 = point1 x2, y2 = point2 # 把两次点击的坐标取出来 distance = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5 os.system('adb shell input swipe 300 400 300 400 {}'.format(int((distance * 1.35)))) # 按下的坐标,抬起的坐标,按压的时间 global need_update need_update = True # time.sleep(1) def on_click(event, coor=[]): # 参数event是点击的位置 x, y = event.xdata, event.ydata # 刚刚点击的坐标 coor.append((x, y)) # 把一次点击的坐标添加到列表 if len(coor) == 2: # 通过坐标的数量,判断当前是否点击了两次 # jump_to_next(coor[0],coor[1]) # coor=[] # 用列表的pop代替上面的方法 jump_to_next(coor.pop(), coor.pop()) def update_screen(frames): global need_update if need_update: time.sleep(1) axes_image.set_array(get_screen_image()) need_update = False return axes_image, figure = plt.figure() # 创建一张空白图片 axes_image = plt.imshow(get_screen_image(), animated=True) # 把截图画到刚才的空白图片对象里面 figure.canvas.mpl_connect('button_press_event', on_click) # 绑定鼠标事件 ani = FuncAnimation(figure, update_screen, interval=300, blit=True) plt.show() # 显示
执行时,需要将手机调成开启USB调试模式,打开微信跳一跳界面,用手机数据线连接电脑。
执行方式:打开命令行工具cmd,进入jump_weixin项目目录,执行python jump.py
会弹出如下图形程序,用鼠标点击开始点与结束点,等待图片刷新后,再次点击开始点与结束点。
好了,大致就是这样了,
看看我刷的(第三的是我,我不是朋友圈里唯一刷分的,强中自有强中手):
是不是瞬间失去了游戏的乐趣?
补充:
C:\Users\lcg>pip install numpy Collecting numpy Downloading numpy-1.14.0-cp36-none-win_amd64.whl (13.4MB) 100% |████████████████████████████████| 13.4MB 75kB/s Installing collected packages: numpy Successfully installed numpy-1.14.0 C:\Users\lcg>pip install matplotlib Collecting matplotlib Downloading matplotlib-2.1.1-cp36-cp36m-win_amd64.whl (8.7MB) 100% |████████████████████████████████| 8.7MB 55kB/s Collecting six>=1.10 (from matplotlib) Downloading six-1.11.0-py2.py3-none-any.whl Requirement already satisfied: numpy>=1.7.1 in c:\python36\lib\site-packages (from matplotlib) Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 (from matplotlib) Downloading pyparsing-2.2.0-py2.py3-none-any.whl (56kB) 100% |████████████████████████████████| 61kB 58kB/s Collecting python-dateutil>=2.0 (from matplotlib) Downloading python_dateutil-2.6.1-py2.py3-none-any.whl (194kB) 100% |████████████████████████████████| 194kB 141kB/s Requirement already satisfied: pytz in c:\python36\lib\site-packages (from matplotlib) Collecting cycler>=0.10 (from matplotlib) Downloading cycler-0.10.0-py2.py3-none-any.whl Installing collected packages: six, pyparsing, python-dateutil, cycler, matplotlib Successfully installed cycler-0.10.0 matplotlib-2.1.1 pyparsing-2.2.0 python-dateutil-2.6.1 six-1.11.0 C:\Users\lcg>pip install pillow Collecting pillow Downloading Pillow-5.0.0-cp36-cp36m-win_amd64.whl (1.6MB) 100% |████████████████████████████████| 1.6MB 199kB/s Installing collected packages: pillow Successfully installed pillow-5.0.0