只有兩個python文件,代碼很簡單。python
shell.py:linux
#coding:utf-8 import subprocess import math import os def execute_command(cmd): print('start executing cmd...') s = subprocess.Popen(str(cmd), stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True) stderrinfo, stdoutinfo = s.communicate() # print('stderrinfo is -------> %s and stdoutinfo is -------> %s' % (stderrinfo, stdoutinfo)) # print('finish executing cmd....') return s.returncode def jump(time): execute_command("adb shell input touchscreen swipe 170 187 170 187 " + str(time)) def screen(): execute_command('adb shell screencap -p /sdcard/jump.png') execute_command('adb pull /sdcard/jump.png ./jump.png') def calcDistance(x1,x2,y1,y2): return math.sqrt((x1 - x2) * (x1 - x2) + (y1-y2) * (y1-y2))
gui.py:git
#coding:utf-8 import os from time import sleep from shell import calcDistance, jump, screen try: # for Python2 import Tkinter as tk ## notice capitalized T in Tkinter except ImportError: # for Python3 import tkinter as tk ## notice lowercase 't' in tkinter here from PIL import Image, ImageTk isFirst=True preX=0 preY=0 def callBack(event): global isFirst,preX,preY,label,tk_image # print(event.x_root, event.y_root) if isFirst: preX = event.x_root preY = event.y_root isFirst= False else: print(event.x_root,preX,event.y_root,preY) distance = calcDistance(event.x_root,preX,event.y_root,preY) time = (int)(distance / 0.35) jump(time) isFirst = True print("distance:" + str(distance) + ",time:" + str(time)) try: sleep(1) except Exception as e: print(e) screen() pil_image = Image.open("./jump.png") # 獲取圖像的原始大小 w, h = pil_image.size # 縮放圖像讓它保持比例,同時限制在一個矩形框範圍內 pil_image_resized = resize(w, h, w_box, h_box, pil_image) # 也能夠顯示縮放後的圖像信息,獲取大小 wr, hr = pil_image_resized.size # convert PIL image object to Tkinter PhotoImage object # 把PIL圖像對象轉變爲Tkinter的PhotoImage對象 tk_image = ImageTk.PhotoImage(pil_image_resized) label.configure(image=tk_image,width=w_box, height=h_box) # label = tk.Label(root, image=tk_image, width=w_box, height=h_box) # padx,pady是圖像與窗口邊緣的距離 # label.pack(padx=5, pady=5) def resize(w, h, w_box, h_box, pil_image): ''''' resize a pil_image object so it will fit into a box of size w_box times h_box, but retain aspect ratio 對一個pil_image對象進行縮放,讓它在一個矩形框內,還能保持比例 ''' f1 = 1.0 * w_box / w # 1.0 forces float division in Python2 f2 = 1.0 * h_box / h factor = min([f1, f2]) # print(f1, f2, factor) # test # use best down-sizing filter width = int(w * factor) height = int(h * factor) return pil_image.resize((width, height), Image.ANTIALIAS) root = tk.Tk() root.title("跳一跳遊戲輔助") # size of image display box you want # 指望圖像顯示的大小 screen()#截屏 pil_image = Image.open("./jump.png") # 獲取圖像的原始大小 w, h = pil_image.size w_box = w/2 h_box = h/2 # 縮放圖像讓它保持比例,同時限制在一個矩形框範圍內 pil_image_resized = resize(w, h, w_box, h_box, pil_image) # 也能夠顯示縮放後的圖像信息,獲取大小 wr, hr = pil_image_resized.size # convert PIL image object to Tkinter PhotoImage object # 把PIL圖像對象轉變爲Tkinter的PhotoImage對象 tk_image = ImageTk.PhotoImage(pil_image_resized) # put the image on a widget the size of the specified display box # Label: 這個小工具,就是個顯示框,小窗口,把圖像大小顯示到指定的顯示框 label = tk.Label(root, image=tk_image, width=w_box, height=h_box) # padx,pady是圖像與窗口邊緣的距離 # label.pack(padx=5, pady=5) label.pack() label.bind("<Button-1>",callBack) root.mainloop()
代碼一看就能懂,請使用python3,有可能須要github
pip3 install pillow
電腦須要配置adb環境變量到path中,支持mac linux windows等shell
運行windows
python3 gui.py
使用方法:api
在電腦上先點擊本身的位置,再點擊目標位置。微信
(僅供學習參考,微信目前刷分好像不怎麼好使了,不少提交不了分數)工具
原版在https://github.com/qiyeboy/LuLunZi/blob/master/WxJmp/,只支持windows,本文修改後的代碼支持其餘平臺了。oop