package main
import ("crypto/md5"
"fmt"
"image/png"
"io/ioutil"
"log"
"os"
"regexp"
"strings"
"bytes"
"os/exec"
"strconv"
"time")const(//可用下面的AdbShellDumpsysActivityF函数获取包名和activity名
APPPackageName = "cn.XXX.android"APP= "cn.XXX.android/com.XXX.XXXActivity")
func main() {//如果手机是休眠状态,则打开电源
ifAdbShellDumpsysPowerOff() {
AdbShellInputKeyEvent("26") //power
}//进入手机主屏
AdbShellInputKeyEvent("4") //back
AdbShellInputKeyEvent("3") //home
/*如果APP未启动,则启动APP
if !strings.Contains(AdbShellDumpsysActivityF(), APPPackageName) {
AdbShellAmStartN(APP)
}*/Tap("设置", 0)
TimeSleepDuration(5)TapOnce(`\d我的`,0, 3, 573)AdbShellInputKeyEvent("26") //power
}//模拟按键,如按下home键,键值参考;https://blog.csdn.net/shililang/article/details/14449527
//adb shell input keyevent 3
func AdbShellInputKeyEvent(s string) {
exec.Command("adb", "shell", "input", "keyevent", s).Run()
}//模拟屏幕点击//有的控件死活抓不到,只能直接点击//adb shell input tap 900 800
func AdbShellInputTap(x, y int) {
x2 :=strconv.Itoa(x)
y2 :=strconv.Itoa(y)
exec.Command("adb", "shell", "input", "tap", x2, y2).Run()
}//模拟滑动//adb shell input swipe 0 0 600 600
func AdbShellInputSwipe(x1, y1, x2, y2 int) {
xx1 :=strconv.Itoa(x1)
yy1 :=strconv.Itoa(y1)
xx2 :=strconv.Itoa(x2)
yy2 :=strconv.Itoa(y2)
exec.Command("adb", "shell", "input", "swipe", xx1, yy1, xx2, yy2).Run()
}//模拟长按 最后一个参数1000表示1秒,可将下面某个参数由500改为501,即允许坐标点有很小的变化。//adb shell input swipe 500 500 500 500 1000
func AdbShellInputSwipeL(x1, y1, x2, y2, t int) {
xx1 :=strconv.Itoa(x1)
yy1 :=strconv.Itoa(y1)
xx2 :=strconv.Itoa(x2)
yy2 :=strconv.Itoa(y2)
exec.Command("adb", "shell", "swipe", "t