SoFunction
Updated on 2024-10-28

Using Python to make WeChat Jumping Aid

1. Preamble

WeChat's jump a jump believe that we are all very familiar with, and now a variety of hangers, aids are also full of flying, anyway, my friends in the rankings have been eight or nine hundred are not surprising. A treasure on a search a bunch of results, the lowest actually as long as more than 3 dollars, want to brush how many points to brush how many points, really outrageous.

As a programmer, I'm determined to do a bit of this myself, for no other reason than to hone my problem-solving skills and for fun. For this kind of task, Python is of course the best choice, with its rich third-party libraries and the characteristics of a glue language.

The main design idea of this program is that the PC adb connects to the cell phone → screenshot → display on the PC → user's mouse selects the starting point and the end point → calculates the distance and duration → adb sends commands to simulate pressing → screenshot cycle.

2.  ADB

adb, Android Debug Bridge, contains the following sections.
-Client, which runs on the development machine, i.e. your development PC, and is used to send adb commands.
-Deamon daemon, running in the debugging device, i.e. debugging the phone or emulator.
-The Server side, running as a background process in the development machine, i.e. your development PC, is used to manage the communication between the Client side in the PC and the Deamon side in the phone.

The adb command we usually use refers to the Client-side program. the Server-side actually listens on port 5037 locally and forwards the commands to the Deamon process on the mobile device via the usb cable/wifi.

Readers of the adb command can check the documentation on the official website (/commands), only a few of the commands used are described here.

(1) adb devices lists all connected emulators/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 screenshot

taking a screenshot of a device display.

adb shell screencap <filename>

adb shell screencap /sdcard/

download the file from the deviceDownloading files from the device to the local machine。

adb pull /sdcard/

(3) adb shell input swipe to simulate a swipe operation (long press)

adb shell input swipe 100 100 100 100 500Analog long-press coordinates(100, 100)length of time500ms

  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) 

Well, the above are the knowledge points of this required adb.

3.  Python

(1) Calling the command line

Python call the command line in a variety of ways, more commonly used (cmd) and (cmd), and (cmd), the three main difference in the return value of the acquisition, the first one can not get the return value, the second and third can be obtained. Which one can be used here, because there is no need to get the return value.

(2)     OpenCV

Mainly use OpenCV to do some image scaling and other operations, it's also possible to use PIL.

(3)     Tkinter

The main use of the Button, PhotoImage two Widget. not much to say.

The implementation of the program is very simple, here in some reasons will not disclose the code, mainly a fine-tuning of the parameters of the process.

Screenshots of the program:

The next step is to combine OpenCV and neural networks to realize automatic recognition and calculation of distance.

For the record, this article is for study and entertainment only.