python跳一跳
参考:https://www.bilibili.com/video/BV1yW411B7iv?t=5297
事前的准备:
adb驱动
手机调到开发者模式,开启USB调试
pycharm
原理
1.获取手机截图
2.点击起点,终点
3.获取坐标
4.算出距离
5.算出按压时间
6.按压松开指令
7.更新截图
实现代码如下:
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 /storage/emulated/0/forjump/screen.jpg‘) os.system(‘adb pull /storage/emulated/0/forjump/screen.jpg‘) return numpy.array(PIL.Image.open(‘screen.jpg‘)) 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*1.35))) 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 updata_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,updata_screen,interval=50,blit=True) plt.show()
结果展示:
不过好像被微信给察觉到可疑的操作了....
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16