用Python寫一個微信跳一跳物理外掛(安卓手機版)

網上好像有很多關於微信跳一跳的外掛,昨天看到有人在教用Python寫的就學了一下

原理:1、通過adb命令截取手機截圖,

2、在截圖上計算兩點之間的距離,

3、算出按壓時間一個像素點的按壓時間是1.35ms

4、再通過adb發送按壓時間的命令


adb驅動很重要,需要先在cmd中運行adb驅動程序。

獲取到截圖後,點擊右邊起始點和目標點,通過程序點擊時間獲取兩點座標,計算距離,算出按壓時間,用adb發送按壓命令。


具體adb工具及及代碼地址:http://download.csdn.net/download/sinat_37921768/10192092

注意:判斷是否發送按壓命令要確認獲取到兩個點後,並在發送按壓時間後把上一次的數據清空,並刷新界面。以下是Python的具體代碼:

import  os
import PIL,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/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
    distace=((y2-y1)**2+(x2-x1)**2)**0.5
    os.system('adb shell input swipe 320 410 320 410 {}'.format(int(distace*1.35)))




def on_calck(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(0.7)
        axes_image.set_array(get_screen_image())
        need_update = False
    return axes_image,




get_screen_image()
figure = plt.figure()
axes_image = plt.imshow(get_screen_image(),animated=True)
figure.canvas.mpl_connect('button_press_event',on_calck)
ani =FuncAnimation(figure,update_screen,interval=50,blit=True)#刷新
plt.show()


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章