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/deviceadb devicesIn response, return serial number and statee4b25377 deviceemulator-5554 device
(2) adb shell screencap截屏
taking a screenshot of a device display.adb shell screencap <filename>adb shell screencap /sdcard/screen.pngdownload 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)
新聞熱點
疑難解答