Skip to content

Commit 0d757e0

Browse files
Added more mouse actions
Added: mouse_left_click mouse_right_click mouse_middle_click all accept a number parameter, this will represent how many times the mouse is clicked
1 parent 5f4f1aa commit 0d757e0

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

AssistantComputerControl/Actions.cs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
using System.Text.RegularExpressions;
1717
using System.Collections.Generic;
1818
using System.Linq;
19-
using System.Drawing;
2019

2120

2221
namespace AssistantComputerControl {
@@ -934,6 +933,63 @@ public void MoveMouse(String parameter) {
934933
}
935934
}
936935

936+
[DllImport("user32.dll", EntryPoint = "mouse_event")]
937+
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
938+
public const int MOUSEEVENTF_LEFTDOWN = 0x02;
939+
public const int MOUSEEVENTF_LEFTUP = 0x04;
940+
public void MouseLeftClick(string parameter) {
941+
// Try to get amount of times to click
942+
if (Int32.TryParse(parameter, out int repeatAmount)) {
943+
for (int count = 0; count < repeatAmount; count++) {
944+
mouse_event(MOUSEEVENTF_LEFTDOWN, Cursor.Position.X, Cursor.Position.Y, 0, 0);
945+
mouse_event(MOUSEEVENTF_LEFTUP, Cursor.Position.X, Cursor.Position.Y, 0, 0);
946+
successMessage = "Simulated pressing the Left mouse button " + repeatAmount + " times";
947+
}
948+
} else {
949+
Error("Repeat amount is not a munber");
950+
}
951+
}
952+
953+
public const int MOUSEEVENTF_RIGHTDOWN = 0x08;
954+
public const int MOUSEEVENTF_RIGHTUP = 0x10;
955+
public void MouseRightClick(string parameter)
956+
{
957+
// Try to get amount of times to click
958+
if (Int32.TryParse(parameter, out int repeatAmount))
959+
{
960+
for (int count = 0; count < repeatAmount; count++)
961+
{
962+
mouse_event(MOUSEEVENTF_RIGHTDOWN, Cursor.Position.X, Cursor.Position.Y, 0, 0);
963+
mouse_event(MOUSEEVENTF_RIGHTUP, Cursor.Position.X, Cursor.Position.Y, 0, 0);
964+
successMessage = "Simulated pressing the Right mouse button " + repeatAmount + " times";
965+
}
966+
}
967+
else
968+
{
969+
Error("Repeat amount is not a munber");
970+
}
971+
}
972+
973+
public const int MOUSEEVENTF_MIDDLEDOWN = 0x20;
974+
public const int MOUSEEVENTF_MIDDLEUP = 0x40;
975+
public void MouseMiddleClick(string parameter)
976+
{
977+
// Try to get amount of times to click
978+
if (Int32.TryParse(parameter, out int repeatAmount))
979+
{
980+
for (int count = 0; count < repeatAmount; count++)
981+
{
982+
mouse_event(MOUSEEVENTF_MIDDLEDOWN, Cursor.Position.X, Cursor.Position.Y, 0, 0);
983+
mouse_event(MOUSEEVENTF_MIDDLEUP, Cursor.Position.X, Cursor.Position.Y, 0, 0);
984+
successMessage = "Simulated pressing the Middle mouse button " + repeatAmount + " times";
985+
}
986+
}
987+
else
988+
{
989+
Error("Repeat amount is not a munber");
990+
}
991+
}
992+
937993
/* End of actions */
938994
}
939995
}

AssistantComputerControl/actionChecker.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,30 @@ public static Actions ExecuteAction(string action, string line, string parameter
522522
actionExecution.MoveMouse(parameter);
523523
}
524524
break;
525+
case "mouse_left_click":
526+
if (String.IsNullOrEmpty(parameter)) {
527+
actionExecution.MouseLeftClick("1");
528+
} else {
529+
actionExecution.MouseLeftClick(parameter);
530+
}
531+
break;
532+
case "mouse_right_click":
533+
if (String.IsNullOrEmpty(parameter)) {
534+
actionExecution.MouseRightClick("1");
535+
} else {
536+
actionExecution.MouseRightClick(parameter);
537+
}
538+
break;
539+
case "mouse_middle_click":
540+
if (String.IsNullOrEmpty(parameter))
541+
{
542+
actionExecution.MouseMiddleClick("1");
543+
}
544+
else
545+
{
546+
actionExecution.MouseMiddleClick(parameter);
547+
}
548+
break;
525549
default:
526550
//Unknown action
527551
actionExecution.errorMessage = "Unknown action \"" + action + "\"";

0 commit comments

Comments
 (0)