Skip to content

Commit 5f4f1aa

Browse files
added move_mouse command
1 parent 0a4ec34 commit 5f4f1aa

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

AssistantComputerControl/Actions.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.Text.RegularExpressions;
1717
using System.Collections.Generic;
1818
using System.Linq;
19+
using System.Drawing;
1920

2021

2122
namespace AssistantComputerControl {
@@ -908,6 +909,31 @@ public void WindowsToast() {
908909
//Todo - quite a bit of work
909910
}
910911

912+
[DllImport("user32.dll", EntryPoint = "SetCursorPos")]
913+
private static extern bool SetCursorPos(int x, int y);
914+
public void MoveMouse(String parameter) {
915+
parameter = parameter.Trim(new char[] { '(',')',' '});
916+
String[] parameterSplit = parameter.Split(',');
917+
918+
// Error Checking
919+
// If there is the correct amount of arguments
920+
if (parameterSplit.Length != 2) {
921+
Error("The parameter is either formatted incorrectly or does not have 2 values");
922+
// If param 1 is a number
923+
} else if ((Int32.TryParse(parameterSplit[0], out int param1))) {
924+
if ((Int32.TryParse(parameterSplit[1], out int param2))) {
925+
SetCursorPos(Int32.Parse(parameterSplit[0]), Int32.Parse(parameterSplit[1]));
926+
successMessage = "Moved Mouse to (" + (Int32.Parse(parameterSplit[0]).ToString() + ", " + Int32.Parse(parameterSplit[1])).ToString() + ")";
927+
} else {
928+
Error("Parameter 2 is not a number");
929+
}
930+
931+
// It isn't a number
932+
} else {
933+
Error("Parameter 1 is not a number");
934+
}
935+
}
936+
911937
/* End of actions */
912938
}
913939
}

AssistantComputerControl/actionChecker.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,11 @@ public static Actions ExecuteAction(string action, string line, string parameter
517517
case "maximize_all":
518518
actionExecution.MaximizeAll();
519519
break;
520+
case "move_mouse":
521+
if (RequireParameter(parameter)) {
522+
actionExecution.MoveMouse(parameter);
523+
}
524+
break;
520525
default:
521526
//Unknown action
522527
actionExecution.errorMessage = "Unknown action \"" + action + "\"";

0 commit comments

Comments
 (0)