最近比较忙,就直接上代码,其中有注释,希望对大家程序开发有所启迪!
实现原理,计算两点距离,反算出需要按压时间,使用adb模拟手机的按压,即可实现微信跳一跳的辅助!
# name: have a jump
# author: DYBOY
# time: 2017-01-06
# charset: utf-8
import os
import PIL
import numpy
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import time
#全局变量
need_update = True
#功能区
#获取截图
def get_screen_image():
os.system('adb shell screencap -p /sdcard/1.png')#获取当前界面的手机截图并保存到根目录
os.system('adb pull /sdcard/1.png') #获取手机中的截图
return numpy.array(PIL.Image.open('1.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 320 410 320 410 {}'.format(int(distance*2.1)))
#绑定的鼠标单击事件
def on_click(event, coor=[]):
global need_update
coor.append((event.xdata, event.ydata))
if len(coor) == 2:
jump_to_next(coor.pop(), coor.pop())
need_update = True
#更新图片
def update_screen(frame):
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=50, blit=True)
plt.show()
值得一提的是,Github上最近传得比较火的一款辅跳一跳助确实写得很厉害,可以自动识别,并且打包成了EXE可执行文件,兼容IOS与Android,还有很多可以学习的地方,以上只是小东个人的理解所写,望多多建议!