-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,625 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
*.exe | ||
|
||
# Folder | ||
bin/ | ||
obj/ | ||
|
||
# Generated files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 2012 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KibotController", "KibotController\KibotController.csproj", "{A141CC1F-ECCA-4900-84BD-B9707E78A1EA}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{A141CC1F-ECCA-4900-84BD-B9707E78A1EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{A141CC1F-ECCA-4900-84BD-B9707E78A1EA}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{A141CC1F-ECCA-4900-84BD-B9707E78A1EA}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{A141CC1F-ECCA-4900-84BD-B9707E78A1EA}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Text; | ||
|
||
namespace KibotController | ||
{ | ||
public class AdbConnect : IConnect | ||
{ | ||
private Log log = null; | ||
private Process p = null; | ||
|
||
public AdbConnect(Log log) | ||
{ | ||
this.log = log; | ||
p = new Process(); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="keyCode"></param> | ||
/// <returns></returns> | ||
public bool InputKey(int keyCode) | ||
{ | ||
string cmd = "shell input keyevent " + keyCode; | ||
string result = executeAdb(cmd); | ||
log.Write(result); | ||
return true; | ||
} | ||
|
||
/// <summary> | ||
/// 输入文本 | ||
/// </summary> | ||
/// <param name="text"></param> | ||
/// <returns></returns> | ||
public bool InputText(string text) | ||
{ | ||
if (text == "") | ||
{ | ||
return false; | ||
} | ||
string cmd = String.Format("shell input text \"{0}\"", text); | ||
string result = executeAdb(cmd); | ||
log.Write("发送\"" + text + "\"成功"); | ||
return true; | ||
} | ||
|
||
/// <summary> | ||
/// 执行命令 | ||
/// </summary> | ||
/// <param name="cmd"></param> | ||
/// <returns></returns> | ||
public bool InputCommand(string cmd) | ||
{ | ||
string result = executeAdb(cmd); | ||
log.Write(result); | ||
return true; | ||
} | ||
|
||
/// <summary> | ||
/// 获取截图并且回传到本地 | ||
/// </summary> | ||
/// <param name="localPath"></param> | ||
/// <returns></returns> | ||
public bool GetScreenShot(string localPath) | ||
{ | ||
string cmdshot = "shell /system/bin/screencap -p /sdcard/screenshot.png"; | ||
string pullFile = "pull /sdcard/screenshot.png \"" + localPath + "\""; | ||
File.Delete(localPath); | ||
executeAdb(cmdshot); | ||
executeAdb(pullFile); | ||
if (File.Exists(localPath)) | ||
{ | ||
log.Write("获取屏幕截图成功"); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/// <summary> | ||
/// 安装本地apk | ||
/// </summary> | ||
/// <param name="apkPath">apk路径</param> | ||
/// <returns></returns> | ||
public bool Install(string apkPath) | ||
{ | ||
string cmd = String.Format("install -r \"{0}\"", apkPath); | ||
string result = executeAdb(cmd); | ||
log.Write(result); | ||
if (result.Contains("Success")) | ||
{ | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/// <summary> | ||
/// 卸载程序包名 | ||
/// </summary> | ||
/// <param name="packageName"></param> | ||
/// <returns></returns> | ||
public bool Uninstall(string packageName) | ||
{ | ||
string cmd = "uninstall " + packageName; | ||
string result = executeAdb(cmd); | ||
log.Write(result); | ||
return false; | ||
} | ||
|
||
private string executeAdb(string cmd) | ||
{ | ||
p.StartInfo.CreateNoWindow = true; | ||
p.StartInfo.FileName = "./adb/adb.exe"; | ||
p.StartInfo.Arguments = cmd; | ||
p.StartInfo.UseShellExecute = false; | ||
p.StartInfo.RedirectStandardError = true; | ||
p.StartInfo.RedirectStandardInput = true; | ||
p.StartInfo.RedirectStandardOutput = true; | ||
p.Start(); | ||
string outStr = p.StandardOutput.ReadToEnd(); | ||
p.Close(); | ||
return outStr; | ||
} | ||
} | ||
} |
Oops, something went wrong.