1. 程式人生 > >用Python寫一個微信跳一跳物理外掛(安卓手機版)

用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()