-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwechat_jump.py
74 lines (54 loc) · 1.65 KB
/
wechat_jump.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from PIL import Image
import math
import time
import os
def pull_screenshot(name = 1):
os.system('adb shell screencap -p /sdcard/{}.png'.format(name))
os.system('adb pull /sdcard/{}.png .'.format(name))
os.system('mv {}.png images/{}.png'.format(name,name))
def jump(distance):
press_time = distance * 1.35
press_time = int(press_time)
cmd = ('adb shell input swipe 320 410 320 410 ' + str(press_time))
print (cmd)
os.system(cmd)
fig = plt.figure()
pull_screenshot()
img = np.array(Image.open(os.path.join('images','1.png')))
click_count = 0
cor = []
name = 1
def update_data(name):
return np.array(Image.open(os.path.join('images','{}.png'.format(name))))
im = plt.imshow(img, animated=True)
def updatefig(*args):
global name
name += 1
pull_screenshot(name = name)
im.set_array(update_data(name))
return im,
def onClick(event):
global ix, iy
global click_count
global cor
# next screenshot
ix, iy = event.xdata, event.ydata
coords = []
coords.append((ix, iy))
print ('now = ', coords)
cor.append(coords)
click_count += 1
if click_count > 1:
click_count = 0
cor1 = cor.pop()
cor2 = cor.pop()
distance = (cor1[0][0] - cor2[0][0])**2 + (cor1[0][1] - cor2[0][1])**2
distance = distance ** 0.5
print ('distance = ', distance)
jump(distance)
fig.canvas.mpl_connect('button_press_event', onClick)
ani = animation.FuncAnimation(fig, updatefig, interval=50, blit=True)
plt.show()