├── .gitignore ├── read_ios.py ├── click_hero.py ├── qutoutiao_android.py ├── read_android.py └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .vscode 3 | venv -------------------------------------------------------------------------------- /read_ios.py: -------------------------------------------------------------------------------- 1 | import wda 2 | import time 3 | import random 4 | 5 | c = wda.Client('http://localhost:8100') 6 | print(c.status()) 7 | 8 | # 打开app,如果传的bundle id为空,默认为当前app 9 | # s = c.session('com.tencent.weread') 10 | s = c.session() 11 | 12 | # 屏幕尺寸 13 | size = s.window_size() 14 | screen_width = size[0] 15 | screen_height = size[1] 16 | print(size) # iPhone 7p: Size(width=414, height=736) 17 | 18 | def print_click(x, y, second): 19 | print(str(round(second, 2)) + '秒后点击(' + str(round(x, 2)) + ', ' + str(round(y, 2)) + ')') 20 | 21 | while 1: 22 | # 随机点击坐标 23 | x = random.uniform(screen_width * 2 / 3 + 20, screen_width - 20) 24 | y = random.uniform(screen_height / 2, screen_height - 50) 25 | second = random.uniform(12, 30) 26 | print_click(x, y, second) 27 | time.sleep(second) 28 | s.tap(x, y) 29 | 30 | -------------------------------------------------------------------------------- /click_hero.py: -------------------------------------------------------------------------------- 1 | import uiautomator2 as u2 2 | import time 3 | import random 4 | import sys 5 | 6 | ip = '' 7 | 8 | # 获取参数,作为ip 9 | argv = sys.argv 10 | if len(argv) > 1: 11 | ip = argv[1] 12 | 13 | # 有ip则是通过wifi连接,否则通过usb adb连接 14 | # 先尝试wifi连接 15 | try: 16 | d = u2.connect(ip) 17 | except: 18 | d = u2.connect() 19 | info = d.info 20 | print(info) # 1920 * 1080 21 | 22 | screen_height = info.get('displayHeight') 23 | screen_width = info.get('displayWidth') 24 | 25 | while 1: 26 | x_center = screen_width / 2 27 | y_center = screen_height / 2 - 100 28 | 29 | # 雷戒 30 | # d.click(x_center, y_center) 31 | # d.click(x_center, y_center - 50) 32 | # d.click(x_center, y_center - 100) 33 | 34 | # 火戒 35 | # time.sleep(.15) 36 | # d.click(x_center, y_center) 37 | 38 | # 冰戒 39 | time.sleep(2) 40 | d.long_click(x_center, y_center, 2) 41 | 42 | -------------------------------------------------------------------------------- /qutoutiao_android.py: -------------------------------------------------------------------------------- 1 | import uiautomator2 as u2 2 | import time 3 | import random 4 | 5 | d = u2.connect() 6 | info = d.info 7 | print(info) # 1920 * 1080 8 | 9 | screen_height = info.get('displayHeight') 10 | screen_width = info.get('displayWidth') 11 | 12 | def print_click(sx, sy, ex, ey, second): 13 | print(str(round(second, 2)) + '秒后拖拽(' + str(round(sx, 2)) + ', ' + str(round(sy, 2)) + '), 到(' + str(round(ex, 2)) + ',' + str(round(ey, 2)) + ')') 14 | 15 | while 1: 16 | sx = random.uniform(20, screen_width / 3 * 2) 17 | sy = random.uniform(screen_height / 2, screen_height - 150) 18 | ex = random.uniform(20, screen_width / 3 * 2) 19 | ey = random.uniform(50, screen_height / 2) 20 | second = random.uniform(20, 40) 21 | print_click(sx, sy, ex, ey, second) 22 | time.sleep(second) 23 | steps = random.uniform(10, 30) 24 | d.swipe(sx, sy, ex, ey, steps) 25 | 26 | 27 | -------------------------------------------------------------------------------- /read_android.py: -------------------------------------------------------------------------------- 1 | import uiautomator2 as u2 2 | import time 3 | import random 4 | import sys 5 | 6 | ip = '' 7 | 8 | # 获取参数,作为ip 9 | argv = sys.argv 10 | if len(argv) > 1: 11 | ip = argv[1] 12 | 13 | # 有ip则是通过wifi连接,否则通过usb adb连接 14 | # 先尝试wifi连接 15 | try: 16 | d = u2.connect(ip) 17 | except: 18 | d = u2.connect() 19 | info = d.info 20 | print(info) # 1920 * 1080 21 | 22 | screen_height = info.get('displayHeight') 23 | screen_width = info.get('displayWidth') 24 | 25 | def print_click(sx, sy, ex, ey, second): 26 | print(str(round(second, 2)) + '秒后拖拽(' + str(round(sx, 2)) + ', ' + str(round(sy, 2)) + '), 到(' + str( 27 | round(ex, 2)) + ',' + str(round(ey, 2)) + ')') 28 | 29 | while 1: 30 | sx = random.uniform(screen_width * 2 / 3, screen_width - 100) 31 | sy = random.uniform(50, screen_height - 100) 32 | ex = random.uniform(20, screen_width / 3) 33 | ey = random.uniform(sy - 200, sy + 200) 34 | second = random.uniform(16, 30) 35 | print_click(sx, sy, ex, ey, second) 36 | time.sleep(second) 37 | steps = random.uniform(0.1, 0.3) 38 | d.swipe(sx, sy, ex, ey, steps) 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 手机端自动触摸工具 2 | 3 | ## 准备工作 + 读书APP自动翻页教程 4 | ### iOS 5 | #### 工具 6 | * Mac 7 | * Xcode 8 | * Python3、pip3 9 | 10 | #### 安装WebDriverAgent 11 | 1. git clone https://github.com/facebook/WebDriverAgent.git 12 | 2. ./Scripts/bootstrap.sh 13 | 3. 打开`WebDriverAgent.xcodeproj`,在Xcode中设置好开发者apple id 14 | 4. 在Xcode中,Product -> **Test**,在手机上运行,在手机上打开一下刚安装的没有图标的WebDriverAgent,会自动关闭,然后在Xcode控制台会输出ServerURL: http://x.x.x.x:8100 15 | 5. brew install imobiledevice 16 | 6. iproxy 8100 8100 17 | 7. 浏览器访问`http://localhost:8100/status`看到json就说明运行成功 18 | 19 | #### 安装python-wda 20 | ``` 21 | pip3 install --pre facebook-wda 22 | ``` 23 | 24 | #### 执行 25 | 以微信读书为例。在微信读书中打开一本书,然后终端执行: 26 | 27 | ``` 28 | git clone https://github.com/huowenxuan/auto_touch 29 | cd auto_touch 30 | python3 read_ios.py 31 | ``` 32 | 33 | ### Android 34 | #### 工具 35 | * Python3、pip3 36 | 37 | #### 安装uiautomator 38 | ``` 39 | pip3 install -U uiautomator2 40 | ``` 41 | 42 | #### 执行 43 | 在读书APP中打开一本书,然后终端执行: 44 | 45 | ``` 46 | git clone https://github.com/huowenxuan/auto_touch 47 | cd auto_touch 48 | ``` 49 | 50 | 如果通过USB控制,需要进入开发者选项,打开USB调试,执行: 51 | 52 | ``` 53 | python3 read_android.py 54 | ``` 55 | 56 | 如果想通过WIFI控制,电脑和手机连接同一WIFI,先连接USB,执行上一步,让手机开启ATX服务后,关闭命令行,拔掉USB,再执行下面的命令。文件名后添加手机的ip地址 57 | 58 | ``` 59 | python3 read_android.py x.x.x.x 60 | ``` 61 | 62 | ## 趣头条小视频自动上拉(仅限android) 63 | 打开趣头条app,点击小视频tab,执行: 64 | 65 | ``` 66 | python3 qutoutiao_android.py 67 | ``` 68 | --------------------------------------------------------------------------------