前言
最近在学习ReactNative,真机调试的时候安装的ADB调试工具,突发奇想,既然PC可以操控手机,是不是可以做一些懒得做的事情
流程
- 通过USB链接真机调试
- 执行wifi调试
adb tcpip 5555 adb connect 手机IP:5555 adb devices
- 如果有连接成功 会显示手机IP的列表,此时会有多个,拔掉USB,只剩一个
- 在nodejs安装模块 node-cmd,编写代码app.js
var nodeCmd = require('node-cmd'); function runCmdTest() { nodeCmd.get( 'adb shell input swipe 800 340 370 202', function (err, data, stderr) { // console.log(data); if(err){ console.log(err); return false } console.log(new Date(),'翻页') } ); nodeCmd.run('adb shell input swipe 800 340 370 202'); }; // runCmdTest() setInterval(runCmdTest,5000)
- 打开微信读书一本书,运行该脚本 ,其核就是adb shell input swipe 模拟滑动 ,5s一次