美文网首页我爱编程
使用Python制作微信跳一跳半自动外挂

使用Python制作微信跳一跳半自动外挂

作者: 北街58号 | 来源:发表于2018-04-15 06:22 被阅读107次

思路

1.截取安卓手机当前屏幕图片并复制到Mac。 知识点:ADB

2.测量截图中两方块之间的距离。知识点:Matplotlib制图工具

3.根据距离判断手机所需按下的时间

4.通过鼠标控制Android触摸屏。知识点:ADB

知识点:

1. ADB Android Bridge

安装方法:https://www.jianshu.com/p/1b3fb1f27b67 。安装页面下方的命令行工具即可。

截屏命令:https://blog.csdn.net/u012283902/article/details/79186354

模拟按键与输入:https://www.cnblogs.com/lybolg/p/7308745.html

2. Matplotlib制图工具:

numpy初级教学视频

Matplotlib初级教学视频

通过PIL Numpy制作Matplotlib图

Matplotlib鼠标事件

思路实现:

1.截取安卓手机当前屏幕图片并复制到电脑。

def get_screen_image():
    global n
    #通过ADB命令截图
    os.system('adb shell screencap -p /sdcard/screen.png')
    #通过ADB命令复制图片到本地
    os.system('adb pull /sdcard/screen.png /Users/songfei/Downloads')
    #通过PIL.Image 和numpy读图
    p = im.open('/Users/XXXXXX/Downloads/screen.png')
    n = np.array(p)
    
get_screen_image()
fig = plt.figure()
#根据读图数据n画图
plt.imshow(n,animated=True)
cid = fig.canvas.mpl_connect('button_press_event', onclick)
plt.show()

2.测量截图中两方块之间的距离。

1)Matplotlib中,用鼠标点击一下方块,得到一个鼠标事件event。event.x 就是x坐标,event.y 就是y坐标。

2)连续传入2个(x,y),就可以在函数onclick()中计算两坐标之间的距离。

3)传入方式:fig.canvas.mpl_connect('button_press_event',onclick)
把'buttom_press_event'这个鼠标按下事件event作为参数传入onclick()函数。

#定义一个列表coor,用来存储2个坐标
coor=[]
def onclick(event):
    global coor,finish
    print('点击坐标:(%d,%d)'%(event.x, event.y))
    if len(coor)<2:
        coor.append((event.x, event.y))
    if len(coor)==2:
        x1 = coor[0][0]
        y1 = coor[0][1]
        x2 = coor[1][0]
        y2 = coor[1][1]
        #勾股定理得斜边长
        l = (abs((x2-x1)**2 + (y2-y1)**2))**0.5
        coor = []
cid = fig.canvas.mpl_connect('button_press_event', onclick)

3.根据距离判断手机所需按下的时间

距离越长,所需蓄力时间越大。经多次测算,距离乘以7相对准确,其实7略大

press_time = int(l*6.5)

4.通过鼠标控制Android触摸屏。

adb中swipe滑动命令有时间参数,可以用来模拟触摸时间

def press_screen(l):
    press_time = int(l*6.5)
    cmd = 'adb shell input swipe %s %s %s %s %s' % (x1,y1,x2,y2,press_time)
    os.system(cmd)

完整代码:

from PIL import Image as im
import numpy as np
import matplotlib.pyplot as plt
import os
import time

#定于坐标列表
coor = []
x1=0
x2=0
y1=0
y2 = 0
n=None
def get_screen_image():
    global n
    os.system('adb shell screencap -p /sdcard/screen.png')
    os.system('adb pull /sdcard/screen.png /Users/songfei/Downloads')
    p = im.open('/Users/songfei/Downloads/screen.png')
    n = np.array(p)

def onclick(event):
    global coor,finish
    print('点击坐标:(%d,%d)'%(event.x, event.y))
    if len(coor)<2:
        coor.append((event.x, event.y))
    if len(coor)==2:
        l = distance(coor)
        print ('两点间距离:',l)
        press_screen(l)
        coor = []
        refresn_screen_image() 

def distance(coor):
    global x1,x2,y1,y2
    x1 = coor[0][0]
    y1 = coor[0][1]
    x2 = coor[1][0]
    y2 = coor[1][1]
    l = (abs((x2-x1)**2 + (y2-y1)**2))**0.5
    return l

def press_screen(l):
    press_time = int(l*6.5)
    cmd = 'adb shell input swipe %s %s %s %s %s' % (x1,y1,x2,y2,press_time)
    print ('蓄力时间:%sms'%press_time)
    os.system(cmd)

def refresn_screen_image():
        plt.close()
        time.sleep(1)
        get_screen_image()
        fig = plt.figure()
        image = plt.imshow(n,animated=True)
        cid = fig.canvas.mpl_connect('button_press_event', onclick)
        plt.show()

get_screen_image()
fig = plt.figure()
plt.imshow(n,animated=True)
cid = fig.canvas.mpl_connect('button_press_event', onclick)
plt.show()

原文地址

相关文章

网友评论

    本文标题:使用Python制作微信跳一跳半自动外挂

    本文链接:https://www.haomeiwen.com/subject/hcarkftx.html