Skip to content

Commit 4fca53e

Browse files
committed
Add EnterText command
1 parent f426172 commit 4fca53e

10 files changed

+171
-20
lines changed

BotEngineClient/BOTConfig.cs

+3
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ public Command(BotEngine.ValidCommandIds selectedCommand)
250250
case BotEngine.ValidCommandIds.EnterLoopCoordinate:
251251
Value = string.Empty;
252252
break;
253+
case BotEngine.ValidCommandIds.EnterText:
254+
Value = String.Empty;
255+
break;
253256
case BotEngine.ValidCommandIds.FindClick:
254257
ImageName = String.Empty;
255258
IgnoreMissing = false;

BotEngineClient/BotEngine.cs

+18
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public enum ValidCommandIds
6262
Drag,
6363
Exit,
6464
EnterLoopCoordinate,
65+
EnterText,
6566
FindClick,
6667
FindClickAndWait,
6768
IfExists,
@@ -1156,6 +1157,23 @@ private CommandResults ExecuteCommand(Command command, Object? additionalData, A
11561157
ADBSendKeys(((XYCoords)additionalData).Y.ToString());
11571158
}
11581159
break;
1160+
case ValidCommandIds.EnterText:
1161+
if (command.Value == null)
1162+
{
1163+
_logger.LogError("Command {0} Error Value is null", command.CommandId);
1164+
results = CommandResults.InputError;
1165+
}
1166+
string commandValue = command.Value;
1167+
if (actionActivity.CommandValueOverride != null && command.OverrideId != null)
1168+
{
1169+
if (actionActivity.CommandValueOverride.ContainsKey(command.OverrideId))
1170+
{
1171+
if (actionActivity.CommandValueOverride[command.OverrideId] != null)
1172+
commandValue = actionActivity.CommandValueOverride[command.OverrideId];
1173+
}
1174+
}
1175+
ADBSendKeys(commandValue);
1176+
break;
11591177
case ValidCommandIds.FindClick:
11601178
if (command.ImageName == null)
11611179
{

BotEngineClient/JsonHelper.cs

+1
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ private void ValidateCommands(string location, string listItemName, JsonArray co
450450
case BotEngine.ValidCommandIds.Exit:
451451
break;
452452
case BotEngine.ValidCommandIds.EnterLoopCoordinate:
453+
case BotEngine.ValidCommandIds.EnterText:
453454
ValidateJsonValue(location, listItemName, "Value", commandsObject, JsonValueKind.String);
454455
break;
455456
case BotEngine.ValidCommandIds.FindClick:

ScriptEditor/CommandSelect.Designer.cs

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ScriptEditor/CommandSelect.cs

+6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ private void LbCommands_SelectedIndexChanged(object sender, EventArgs e)
5858
rtbCommandHelp.Rtf = @"{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang3081{\fonttbl{\f0\fnil\fcharset0 Calibri;}}\viewkind4\uc1\pard\sa200\sl276\slmult1
5959
\b\fs32 Enter Loop Coordinate\par
6060
\b0\fs22 This command will enter the text associated with the coordinate part (X/Y) from the list selected via \b Loop Coordinates\b0 .\par
61+
}";
62+
break;
63+
case ValidCommandIds.EnterText:
64+
rtbCommandHelp.Rtf = @"{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang3081{\fonttbl{\f0\fnil\fcharset0 Calibri;}}\viewkind4\uc1\pard\sa200\sl276\slmult1
65+
\b\fs32 Enter Text\par
66+
\b0\fs22 This command will enter the text that you assign via the Android Keyboard.\par
6167
}";
6268
break;
6369
case ValidCommandIds.FindClick:

ScriptEditor/ScriptEditor.Designer.cs

+88-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ScriptEditor/ScriptEditor.cs

+35
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public ScriptEditor()
6464
ResetGroupBox(gbImageArea);
6565
ResetGroupBox(gbList);
6666
ResetGroupBox(gbLoops);
67+
ResetGroupBox(gbEnterText);
6768

6869
this.Size = new Size(800, 485);
6970
splitContainer1.SplitterDistance = 320;
@@ -1242,6 +1243,26 @@ private void TvBotData_AfterSelect(object sender, TreeViewEventArgs e)
12421243
gbLoopCoordinate.Enabled = true;
12431244
gbLoopCoordinate.Visible = true;
12441245
break;
1246+
case ValidCommandIds.EnterText:
1247+
if (commandCopy.Value != null)
1248+
{
1249+
tbEnterTextText.Text = commandCopy.Value;
1250+
}
1251+
else
1252+
{
1253+
tbEnterTextText.Text = string.Empty;
1254+
}
1255+
if (commandCopy.OverrideId != null)
1256+
{
1257+
tbEnterTextOverideId.Text = commandCopy.OverrideId;
1258+
}
1259+
else
1260+
{
1261+
tbEnterTextOverideId.Text = string.Empty;
1262+
}
1263+
gbEnterText.Enabled = true;
1264+
gbEnterText.Visible = true;
1265+
break;
12451266
case ValidCommandIds.FindClick:
12461267
if (!string.IsNullOrEmpty(commandCopy.ImageName))
12471268
cbImageNameNoWait.SelectedItem = commandCopy.ImageName;
@@ -1804,6 +1825,7 @@ private string GetCommandIdDisplayText(Command command)
18041825
childText = string.Format("{0} ({1}, {2}) - ({3}, {4})", command.CommandId, command.Swipe.X1, command.Swipe.Y1, command.Swipe.X2, command.Swipe.Y2);
18051826
break;
18061827
case ValidCommandIds.EnterLoopCoordinate:
1828+
case ValidCommandIds.EnterText:
18071829
if (command.Value != null)
18081830
childText = string.Format("{0} ({1})", command.CommandId, command.Value);
18091831
break;
@@ -1905,6 +1927,8 @@ private void ResetEditFormItems()
19051927
btnUpdate.Enabled = false;
19061928
gbLoops.Enabled = false;
19071929
gbLoops.Visible = false;
1930+
gbEnterText.Enabled = false;
1931+
gbEnterText.Visible = false;
19081932
}
19091933

19101934
/// <summary>
@@ -2093,6 +2117,17 @@ private void BtnUpdate_Click(object sender, EventArgs e)
20932117
commandCopy.Value = "Y";
20942118
}
20952119
break;
2120+
case ValidCommandIds.EnterText:
2121+
commandCopy.Value = tbEnterTextText.Text;
2122+
if (tbEnterTextOverideId.Text.Length > 0)
2123+
{
2124+
commandCopy.OverrideId = tbEnterTextOverideId.Text;
2125+
}
2126+
else
2127+
{
2128+
commandCopy.OverrideId = null;
2129+
}
2130+
break;
20962131
case ValidCommandIds.FindClick:
20972132
commandCopy.ImageName = (string)cbImageNameNoWait.SelectedItem;
20982133
commandCopy.IgnoreMissing = cbIgnoreMissing.Checked;

TestBotEngineClient/TestData/InvalidGameConfig_EverythingElse.json

+11
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,17 @@
524524
"ImageName": "ValidFindString"
525525
}
526526
]
527+
},
528+
"EnterTextWrongType": {
529+
"Frequency": 1,
530+
"ActionType": "System",
531+
"Commands": [
532+
{
533+
"CommandNumber": 10,
534+
"CommandId": "EnterText",
535+
"Value": 0
536+
}
537+
]
527538
}
528539
},
529540
"actions": {

TestBotEngineClient/TestData/ValidGameConfig.json

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@
5858
"CommandId": "StartGame",
5959
"TimeOut": 120000,
6060
"Value": "com.android.chrome/com.android.chrome/com.google.android.apps.chrome.Main"
61+
},
62+
{
63+
"CommandNumber": 1020,
64+
"CommandId": "EnterText",
65+
"Value": "Text To Enter"
6166
}
6267
]
6368
}

0 commit comments

Comments
 (0)