diff --git a/Directory.Packages.props b/Directory.Packages.props index 4b450020..b51dfc1e 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -38,7 +38,7 @@ - + diff --git a/src/Plugins/BotSharp.Plugin.OsDriver/WinOSDriver.cs b/src/Plugins/BotSharp.Plugin.OsDriver/WinOSDriver.cs index 45a2572d..2ed39994 100644 --- a/src/Plugins/BotSharp.Plugin.OsDriver/WinOSDriver.cs +++ b/src/Plugins/BotSharp.Plugin.OsDriver/WinOSDriver.cs @@ -29,6 +29,10 @@ public class WinOSDriver : IComputerUse case "right_click": WindowsMouseController.RightClick(); break; + case "cursor_position": + var (x, y) = WindowsMouseController.GetCurrentCursorPosition(); + Console.WriteLine($"Current cursor position: ({x}, {y})"); + break; default: throw new ToolError($"Action {action} is not supported"); } diff --git a/src/Plugins/BotSharp.Plugin.OsDriver/WindowsMouseController.cs b/src/Plugins/BotSharp.Plugin.OsDriver/WindowsMouseController.cs index c604780f..8e54d8c1 100644 --- a/src/Plugins/BotSharp.Plugin.OsDriver/WindowsMouseController.cs +++ b/src/Plugins/BotSharp.Plugin.OsDriver/WindowsMouseController.cs @@ -13,6 +13,13 @@ public class WindowsMouseController public int Left, Top, Right, Bottom; } + [StructLayout(LayoutKind.Sequential)] + public struct POINT + { + public int X; + public int Y; + } + // Define MONITORINFO structure [StructLayout(LayoutKind.Sequential)] public struct MONITORINFO @@ -34,6 +41,10 @@ public class WindowsMouseController [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern bool GetMonitorInfo(IntPtr hMonitor, ref MONITORINFO lpmi); + [DllImport("user32.dll")] + private static extern bool GetCursorPos(out POINT lpPoint); + + // Class to hold monitor information public class MonitorInfo { @@ -41,6 +52,13 @@ public class WindowsMouseController public RECT MonitorArea; } + // Method to get current cursor position + public static (int x, int y) GetCurrentCursorPosition() + { + GetCursorPos(out POINT cursorPos); + return (cursorPos.X, cursorPos.Y); + } + // Method to get all connected monitors public static List GetMonitors() {