微信小游戏“跳一跳”,为了刷分数,写一个游戏辅助工具。
程序中使用的工具
1.ADB驱动,这个需要配置环境变量
2.http://download.youkuaiyun.com/download/lt_zl/10201117
第二个和第三个程序一个是手机上的,一个是电脑上的。打开USB调试。
这三个资源有链接;
3.cmd命令中使用adb命令
adb环境变量配置好之后,在cmd中输入"adb shell" 会出现一个"$",表示环境没有问题.
adb shell input touchscreen swipe 180 178 180 178 1000;
//这个命令时模拟手机的点击时间,最后一个参数是时间参数(单位是毫秒)
4.java代码
//cmd命令
String cmd ="adb shell input touchscreen swipe 180 187 180 187 "+Math.round(sqrt*6);
Runtime runtime = Runtime.getRuntime();
//执行命令
try {
Process p = runtime.exec(cmd);
System.out.println(cmd);
int waitFor = p.waitFor();
System.out.println("waitFor:"+waitFor);
//读取标准输入流
nputStream iStream = p.getInputStream();
InputStreamReader iStreamReader = new InputStreamReader(iStream);
BufferedReader bReader = new BufferedReader(iStreamReader);
String readLine = bReader.readLine();
System.out.println("readLine:"+readLine);
InputStream errorStream = p.getErrorStream();
// 用一个读输出流类去读
InputStreamReader is = new InputStreamReader(errorStream);
// 用缓冲器读行
BufferedReader br1 = new BufferedReader(is);
String line1 = null;
StringBuilder sb1 = new StringBuilder();
line1 = br1.readLine();
System.out.println(line1);
while ((line1 = br1.readLine()) != null) {
System.out.println("---"+line1);
sb1.append(line1);
}
System.out.println(sb1.toString());
errorStream.close();
System.out.println("end");
is.close();
br1.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
这边因为对RunTime不是太了解,所以最后程序没有跑通,希望有哦