1. 程式人生 > >微信跳一跳輔助工具(Python)

微信跳一跳輔助工具(Python)

1.準備工具

  • adb驅動 –> 最好下載最新的版本,因為安卓對系統的效能有所提高,對驅動的要求也更高 ( 連結:https://pan.baidu.com/s/1qZqAxT6 密碼:61xo)
  • 安卓手機 –>蘋果手機僅僅只是驅動不同,故而程式程式碼會略有不同
  • 開啟手機除錯模式 –> 根據手機版本,請自行百度
  • usb線接好手機和電腦 –>保證電腦的埠驅動沒有問題,手機usb除錯模式開啟

2.實現原理

  • 獲取手機的實時截圖
  • 點選開始位置和結束位置
  • 計算兩個點的距離
  • 計算按壓時間
  • 傳送按壓指令
  • 重新重新整理手機截圖

3.Python程式碼

#!/usr/bin/env python
#coding=utf-8 import os import PIL,numpy import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation import time need_update = True def get_screen_images(): 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 320 410 320 410 {}'.format(int(distance*2.00))) def on_click(event, coor=[]): #[(x1,y1),(x2,y2)] 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() need_update = False return axes_image, figure = plt.figure() #建立一個空白的圖片物件 axes_image = plt.imshow(get_screen_images(),animated=True) #把獲取的照片畫在座標軸上 figure.canvas.mpl_connect('button_press_event', on_click) ani = FuncAnimation(figure, update_screen, interval=50, blit=True) plt.show()

注意:
- func():返回的結果是值
- func:返回的是物件

模組在import後,如果顯示錯誤,請按照你習慣的方式進行必要的安裝
  • import os :匯入系統模組,以方便電腦可以操控手機
  • import PIL :匯入影象處理標準庫,以方便操作圖片
  • import numpy:匯入numpy模組,可用來儲存和處理大型矩陣
  • import matplotlib:匯入科學計算庫,達到快速計算的效果
  • import time:匯入時間函式庫,以方便延遲操作

4.操作說明

  • 執行Python程式
  • 在程式生成的圖片中,用滑鼠點選起始位置和結束位置
    這裡寫圖片描述
  • 手機客戶端會發現跳一跳的外掛已經開始執行了~