package main
import (
"net/http"
"fmt"
"os/exec"
"os"
"time"
)
func index(w http.ResponseWriter,r *http.Request){
r.ParseForm()
x:=r.FormValue("x")
y:=r.FormValue("y")
// 测试打印 x y 的值
//fmt.Fprint(w,string(x+y))
// 输入中文
//comand:="am broadcast -a ADB_INPUT_TEXT --es msg '"+word+"'"
//点击指定位置
comand:="input tap "+x+" "+y
cmd:=exec.Command(os.Getenv("SHELL"),"-c",comand)
bytes,err:=cmd.Output()
if err!=nil{
fmt.Println(err)
}
resp:=string(bytes)
// 休眠 300毫秒
time.Sleep(300*time.Millisecond)
cmd.Process.Kill()
fmt.Fprint(w, string(comand+resp))
}
func main() {
http.HandleFunc("/",index)
err:=http.ListenAndServe(":9091",nil)
if err !=nil{
fmt.Println(err)
}
}
网友评论