1. 前言
微信的跳一跳相信大家都很熟悉了, 而且现在各种外挂, 辅助也是满天飞, 反正本人的好友排行榜中已经是八九百都不足为奇了. 某宝上一搜一堆结果, 最低的居然只要 3 块多, 想刷多少分就刷多少分, 真是离谱.
作为一枚程序猿, 我决心也自己搞一下, 不为别的, 一来为了磨练一下自己的解决问题的能力, 而来也为了娱乐一下. 像这种任务, 最适合的当然是 Python, 丰富的第三方库, 而且具有胶水语言的特点.
本程序的主要设计思路就是, PC 端 adb 连接手机→截屏→在 PC 端展示→用户鼠标选取起点和终点→计算距离, 时长→adb 发送指令模拟按压→截屏循环.
2. ADB
adb,Android Debug Bridge, 即安卓调试桥, 包含如下几个部分:
Client 端, 运行在开发机器中, 即你的开发 PC 机, 用来发送 adb 命令
Deamon 守护进程, 运行在调试设备中, 即的调试手机或模拟器
Server 端, 作为一个后台进程运行在开发机器中, 即你的开发 PC 机, 用来管理 PC 中的 Client 端和手机的 Deamon 之间的通信
我们通常用的 adb 命令指的就是 Client 端程序. Server 端实际上在本机侦听端口 5037, 将指令通过 usb 线 / wifi 转发给移动设备的 Deamon 进程.
adb 命令读者可以去官方网站查看文档 (http://adbshell.com/commands), 这里只介绍用到的几个命令.
(1) adb devices 列出所有连接的模拟器 / 设备
Prints a list of all attached emulator/device
adb devices
In response, return serial number and state
e4b25377 device
emulator-5554 device
(2) adb shell screencap 截屏
taking a screenshot of a device display.
adb shell screencap <filename>
adb shell screencap /sdcard/screen.png
download the file from the device 将文件从设备下载到本机.
adb pull /sdcard/screen.png
(3) adb shell input swipe 模拟滑动操作 (长按)
adb shell input swipe 100 100 100 100 500 模拟长按坐标 (100, 100) 时长 500ms
C: \Documents and Settings\Administrator > adb shell root@NX403A: / # input
input
Usage: input [<source>] <command> [<arg>...]
The sources are:
trackball
joystick
touchnavigation
mouse
keyboard
gamepad
touchpad
dpad
stylus
touchscreen
The commands and default sources are:
text <string> (Default: touchscreen)
keyevent [--longpress] <key code number or name> ... (Default: keyboard)
tap <x> <y> (Default: touchscreen)
swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)
press (Default: trackball)
roll <dx> <dy> (Default: trackball)/
好了, 以上是本次所需 adb 的知识点.
3. Python
(1) 调用命令行
Python 调用命令行有多种方式, 比较常用的是 os.system(cmd) 和 os.popen(cmd), 以及 commands.getoutput(cmd), 这三者主要区别在返回值的获取方面, 第一个无法获得返回值, 第二, 三个则可以获取. 这里用哪个都可以, 因为不需要获得返回值.
(2) OpenCV
主要用 OpenCV 做一些图片缩放等操作, 用 PIL 也是可以的.
(3) Tkinter
主要用到了 Button,PhotoImage 这两个 Widget. 不多说了.
程序的实现是很简单的, 这里处于某些原因就不公开代码了, 主要就是一个细调参数的过程.
程序截图:
来源: https://www.cnblogs.com/pleiades/p/8387934.html