|
16 | 16 | using System.Text.RegularExpressions; |
17 | 17 | using System.Collections.Generic; |
18 | 18 | using System.Linq; |
19 | | -using System.Drawing; |
20 | 19 |
|
21 | 20 |
|
22 | 21 | namespace AssistantComputerControl { |
@@ -934,6 +933,63 @@ public void MoveMouse(String parameter) { |
934 | 933 | } |
935 | 934 | } |
936 | 935 |
|
| 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 | + |
937 | 993 | /* End of actions */ |
938 | 994 | } |
939 | 995 | } |
0 commit comments