Skip to content

Commit de03268

Browse files
committed
Add cursor_position for OsDriver.
1 parent 4325bfe commit de03268

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<PackageVersion Include="Nanoid" Version="3.1.0" />
3939
<PackageVersion Include="Swashbuckle.AspNetCore" Version="8.1.2" />
4040
<PackageVersion Include="System.Security.Cryptography.Pkcs" Version="8.0.1" />
41-
<PackageVersion Include="Anthropic.SDK" Version="5.1.1" />
41+
<PackageVersion Include="Anthropic.SDK" Version="5.5.0" />
4242
<PackageVersion Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
4343
<PackageVersion Include="NAudio" Version="2.2.1" />
4444
<PackageVersion Include="NAudio.Core" Version="2.2.1" />

src/Plugins/BotSharp.Plugin.OsDriver/WinOSDriver.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public static void TakeAction(string action, string? text, Tuple<int, int>? coor
2929
case "right_click":
3030
WindowsMouseController.RightClick();
3131
break;
32+
case "cursor_position":
33+
var (x, y) = WindowsMouseController.GetCurrentCursorPosition();
34+
Console.WriteLine($"Current cursor position: ({x}, {y})");
35+
break;
3236
default:
3337
throw new ToolError($"Action {action} is not supported");
3438
}

src/Plugins/BotSharp.Plugin.OsDriver/WindowsMouseController.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ public struct RECT
1313
public int Left, Top, Right, Bottom;
1414
}
1515

16+
[StructLayout(LayoutKind.Sequential)]
17+
public struct POINT
18+
{
19+
public int X;
20+
public int Y;
21+
}
22+
1623
// Define MONITORINFO structure
1724
[StructLayout(LayoutKind.Sequential)]
1825
public struct MONITORINFO
@@ -34,13 +41,24 @@ private static extern bool EnumDisplayMonitors(IntPtr hdc, IntPtr lprcClip,
3441
[DllImport("user32.dll", CharSet = CharSet.Auto)]
3542
private static extern bool GetMonitorInfo(IntPtr hMonitor, ref MONITORINFO lpmi);
3643

44+
[DllImport("user32.dll")]
45+
private static extern bool GetCursorPos(out POINT lpPoint);
46+
47+
3748
// Class to hold monitor information
3849
public class MonitorInfo
3950
{
4051
public IntPtr MonitorHandle;
4152
public RECT MonitorArea;
4253
}
4354

55+
// Method to get current cursor position
56+
public static (int x, int y) GetCurrentCursorPosition()
57+
{
58+
GetCursorPos(out POINT cursorPos);
59+
return (cursorPos.X, cursorPos.Y);
60+
}
61+
4462
// Method to get all connected monitors
4563
public static List<MonitorInfo> GetMonitors()
4664
{

0 commit comments

Comments
 (0)