Auto.JS Tutorial

Original link: https://blog.csdn.net/QiHsMing/article/details/86762007

Disclaimer: This tutorial is based b main station up - pen Qingju video. Portal: https://space.bilibili.com/21486893/video

Auto.JS

Auto.jsIs based JavaScriptscripting language framework running on the Android platform. Auto.js main operating principle is based ancillary services AccessibilityService.

Features:

  1. Data monitoring: You can monitor the current data of the phone.
  2. Image Monitoring: Screenshots Get the current page information.
  3. Control Operation: Analog phones operate controls.
  4. Workflow automation: write a simple script to complete the series of automated operations. Such as: micro-channel / QQ thumbs automatic, fast grab a single like.
  5. Timing function: timing of the implementation of a script, the timing to complete the task. Such as: the timing and the like check punch.

Project Introduction:

Phone installation steps:

① turn on accessibility service
Here Insert Picture Description
Here Insert Picture Description
key to stop the script on ② volume: When a script is in the state can not be stopped, use the volume keys forcibly stop the script.
Here Insert Picture Description
③ Open Window suspension:
Here Insert Picture Description
suspension window has four controls:

1)脚本列表
2)自动录制
3)布局范围分析布局层次分析

4)更多

Here Insert Picture Description

auto的优点:

1)开源:代码开源,可以查到源码。

2)无需root:Android 7.0以上功能基本不需要root。

3)免费。

4)易用:代码自动生成。

5)语言:标准的JS语法。

6)灵活。

7)扩展:提供JS转JAVA桥梁,存在无限多的扩展。

提倡自动动手编写Auto.JS脚本

1)安全:Auto.JS脚本拥有很大的权限,使用他人的脚本可能存在风险。

2)编写简单:JS 脚本嵌套中文,方便阅读和书写。

3)脚本升级:一旦APP版本升级,原脚本可能不使用了。

4)提升自己的编写代码能力和解决问题能力。

PC环境的搭建

VS Code 安装

VS Code 入门教程:https://blog.csdn.net/QiHsMing/article/details/87064955

Visual Studio Code 官方下载地址:https://code.visualstudio.com 根据你的电脑平台选择版本下载。
Here Insert Picture Description
新建项目文件夹,右键点击 Open with Code 在VS Code 中打开。
Here Insert Picture Description

安装 AutoJS 插件

点击 扩展 搜索 Auto.jshyb1996 即可找到Auto.JS插件。
Here Insert Picture Description

使用AutoJS插件开发

1.开启AutoJS插件

按 Ctrl+Shift+P 或点击"查看"->"命令面板"可调出命令面板,输入 Auto.js 可以看到几个命令,移动光标到命令Auto.js: Start Server,按回车键执行该命令。

Here Insert Picture Description
此时VS Code会在右上角显示"Auto.js server running",即开启服务成功。
Here Insert Picture Description
2.连接手机终端

将手机连接到电脑启用的Wifi或者同一局域网中。通过命令行ipconfig(或者其他操作系统的相同功能命令)查看电脑的IP地址。在Auto.js的侧拉菜单中启用调试服务,并输入IP地址,等待连接成功。
Here Insert Picture Description
Here Insert Picture Description
一旦连接成功,VS Code 显示:
Here Insert Picture Description

在电脑上编辑JavaScript文件并通过命令Run或者按键F5在手机上运行。
Here Insert Picture Description
手机终端运行结果:
Here Insert Picture Description

3.保存项目到手机终端
按 Ctrl+Shift+P 或点击"查看"->"命令面板"可调出命令面板,输入以下命令,会找到已连接手机终端。

  Auto.js:SaveToDevice

   
   
  • 1

Here Insert Picture Description
点击已连接手机终端,项目就会保存到已连接手机终端。
Here Insert Picture Description
Here Insert Picture Description

AutoJS插件常用命令

按 Ctrl+Shift+P 或点击"查看"->"命令面板"可调出命令面板,输入 Auto.js 可以看到几个命令:

Start Server: Start the plug-in service. After ensuring mobile phones and computers in the case of the same regional network in Auto.js side connected to the computer using the pull-down menu functions connected.
Stop Server: Stop the plug-in service.
RunThe script is currently running editor. If multiple devices are connected, it is run on all devices.
RerunStop script corresponding to the current file and re-run. If you have multiple devices connected, all devices rerun.
StopStop the current file corresponding to the script. If multiple devices are connected, it is stopped in all devices.
StopAllStop all scripts that are running. If you have multiple devices connected, all scripts run on all devices.
SaveSave the current file to the phone's default script directory (file name prefixed with remote). If you have multiple devices connected, all stored in the device.
RunOnDevice: Device pop-up menu and specify the device run the script.
SaveToDevice:Device pop-up menu and save the script in the specified device.
New Project(New Item): Select an empty folder (or create a new file manager in an empty folder), it will automatically create a project
Run Project(Run Project): Running a project that requires more than Auto.js 4.0.4Alpha5 support
Save Project(save project): saving a project that requires more support Auto.js 4.0.4Alpha5

Corresponding to the above command some shortcuts, to be described later with reference to a command.

Simple Script Example: to achieve micro-channel friend punctuate Chan

step:

  1. Found Comment button
  2. Click the comment button
  3. Find the point Like button
  4. Click the thumbs up button

Code:

评论=desc("评论").findOne();
log(评论);
评论.click();
sleep(1000);
赞 = text("赞").findOne();
赞的父控件 = 赞.parent();
赞的父控件.click();	

Guess you like

Origin blog.csdn.net/weixin_43560272/article/details/102736107