diff --git a/docs/articles/overview-of-wrapper-and-api.md b/docs/articles/overview-of-wrapper-and-api.md index c1954aa..70db05d 100644 --- a/docs/articles/overview-of-wrapper-and-api.md +++ b/docs/articles/overview-of-wrapper-and-api.md @@ -24,7 +24,7 @@ | --- | --- | | AdbScreencapMethods | `MaaAdbScreencapMethod` | | AdbInputMethods | `MaaAdbInputMethod` | -| Win32ScreencapMethod | `MaaWin32ScreencapMethod` | +| Win32ScreencapMethods | `MaaWin32ScreencapMethod` | | Win32InputMethod | `MaaWin32InputMethod` | | MacOSScreencapMethod | `MaaMacOSScreencapMethod` | | MacOSInputMethod | `MaaMacOSInputMethod` | diff --git a/src/MaaFramework.Binding.Native/Extensions/DesktopWindowInfoExtensions.cs b/src/MaaFramework.Binding.Native/Extensions/DesktopWindowInfoExtensions.cs index aa99766..64530b9 100644 --- a/src/MaaFramework.Binding.Native/Extensions/DesktopWindowInfoExtensions.cs +++ b/src/MaaFramework.Binding.Native/Extensions/DesktopWindowInfoExtensions.cs @@ -9,7 +9,7 @@ public static class DesktopWindowInfoExtensions /// Converts a to a . /// /// The DesktopWindowInfo. - /// The screencap method. + /// The screencap methods. /// The mouse method. /// The keyboard method. /// The new handle to a win32 window. @@ -18,7 +18,7 @@ public static class DesktopWindowInfoExtensions /// A MaaWin32Controller. /// public static MaaWin32Controller ToWin32ControllerWith(this DesktopWindowInfo info, - Win32ScreencapMethod? screencapMethod = null, + Win32ScreencapMethods? screencapMethods = null, Win32InputMethod? mouseMethod = null, Win32InputMethod? keyboardMethod = null, nint? hWnd = null, @@ -33,7 +33,7 @@ public static MaaWin32Controller ToWin32ControllerWith(this DesktopWindowInfo in handle, handle == info.Handle ? info.Name : string.Empty, handle == info.Handle ? info.ClassName : string.Empty, - screencapMethod ?? info.ScreencapMethod, + screencapMethods ?? info.ScreencapMethods, mouseMethod ?? info.MouseMethod, keyboardMethod ?? info.KeyboardMethod ), @@ -42,7 +42,7 @@ public static MaaWin32Controller ToWin32ControllerWith(this DesktopWindowInfo in ); } - /// + /// public static MaaWin32Controller ToWin32Controller(this DesktopWindowInfo info, LinkOption link = LinkOption.Start, CheckStatusOption check = CheckStatusOption.ThrowIfNotSucceeded) @@ -57,7 +57,7 @@ public static MaaWin32Controller ToWin32Controller(this DesktopWindowInfo info, /// /// The DesktopWindowInfo. /// The type of virtual gamepad. - /// The screencap method. + /// The screencap methods. /// The new handle to a win32 window. /// Executes if ; otherwise, not link. /// Checks LinkStart().Wait() status if ; otherwise, not check. @@ -65,7 +65,7 @@ public static MaaWin32Controller ToWin32Controller(this DesktopWindowInfo info, /// public static MaaGamepadController ToGamepadControllerWith(this DesktopWindowInfo info, GamepadType gamepadType, - Win32ScreencapMethod? screencapMethod = null, + Win32ScreencapMethods? screencapMethods = null, nint? hWnd = null, LinkOption link = LinkOption.Start, CheckStatusOption check = CheckStatusOption.ThrowIfNotSucceeded) @@ -82,7 +82,7 @@ public static MaaGamepadController ToGamepadControllerWith(this DesktopWindowInf handle, handle == info.Handle ? info.Name : string.Empty, handle == info.Handle ? info.ClassName : string.Empty, - screencapMethod ?? info.ScreencapMethod, + screencapMethods ?? info.ScreencapMethods, Win32InputMethod.None, Win32InputMethod.None ), @@ -91,7 +91,7 @@ public static MaaGamepadController ToGamepadControllerWith(this DesktopWindowInf ); } - /// + /// public static MaaGamepadController ToGamepadController(this DesktopWindowInfo info, GamepadType gamepadType, LinkOption link = LinkOption.Start, diff --git a/src/MaaFramework.Binding.Native/MaaController/MaaGamepadController.cs b/src/MaaFramework.Binding.Native/MaaController/MaaGamepadController.cs index d8f8950..fbfaf29 100644 --- a/src/MaaFramework.Binding.Native/MaaController/MaaGamepadController.cs +++ b/src/MaaFramework.Binding.Native/MaaController/MaaGamepadController.cs @@ -37,7 +37,7 @@ public class MaaGamepadController : MaaController [DebuggerBrowsable(DebuggerBrowsableState.Never)] private string DebuggerInfoString => _debugInfo is null ? "No Screencap" - : $"{nameof(_debugInfo.Name)} = {_debugInfo.Name}, {nameof(_debugInfo.ClassName)} = {_debugInfo.ClassName}, ScreencapMethod = {_debugInfo.ScreencapMethod}"; + : $"{nameof(_debugInfo.Name)} = {_debugInfo.Name}, {nameof(_debugInfo.ClassName)} = {_debugInfo.ClassName}, ScreencapMethods = {_debugInfo.ScreencapMethods}"; /// /// Creates a instance. @@ -54,7 +54,7 @@ public MaaGamepadController(GamepadType gamepadType, DesktopWindowInfo? info = n { var handle = info is null ? MaaGamepadControllerCreate(nint.Zero, (MaaGamepadType)gamepadType, 0UL) - : MaaGamepadControllerCreate(info.Handle, (MaaGamepadType)gamepadType, (MaaWin32ScreencapMethod)info.ScreencapMethod); + : MaaGamepadControllerCreate(info.Handle, (MaaGamepadType)gamepadType, (MaaWin32ScreencapMethod)info.ScreencapMethods); _ = MaaControllerAddSink(handle, MaaEventCallback, (nint)MaaHandleType.Controller); SetHandle(handle, needReleased: true); @@ -67,12 +67,12 @@ public MaaGamepadController(GamepadType gamepadType, DesktopWindowInfo? info = n /// Window handle for screencap (optional, can be if screencap not needed). /// Type of virtual gamepad ( or ). - /// Win32 screencap method to use. Ignored if hWnd is . + /// Win32 screencap methods to use. Ignored if hWnd is . /// Executes if ; otherwise, not link. /// Checks LinkStart().Wait() status if ; otherwise, not check. /// - public MaaGamepadController(nint hWnd, GamepadType gamepadType, Win32ScreencapMethod screencapMethod, LinkOption link = LinkOption.Start, CheckStatusOption check = CheckStatusOption.ThrowIfNotSucceeded) - : this(gamepadType, hWnd == nint.Zero ? null : new(hWnd, string.Empty, string.Empty, screencapMethod, Win32InputMethod.None, Win32InputMethod.None), link, check) + public MaaGamepadController(nint hWnd, GamepadType gamepadType, Win32ScreencapMethods screencapMethods, LinkOption link = LinkOption.Start, CheckStatusOption check = CheckStatusOption.ThrowIfNotSucceeded) + : this(gamepadType, hWnd == nint.Zero ? null : new(hWnd, string.Empty, string.Empty, screencapMethods, Win32InputMethod.None, Win32InputMethod.None), link, check) { } diff --git a/src/MaaFramework.Binding.Native/MaaController/MaaWin32Controller.cs b/src/MaaFramework.Binding.Native/MaaController/MaaWin32Controller.cs index d64d3bd..927e323 100644 --- a/src/MaaFramework.Binding.Native/MaaController/MaaWin32Controller.cs +++ b/src/MaaFramework.Binding.Native/MaaController/MaaWin32Controller.cs @@ -16,7 +16,7 @@ public class MaaWin32Controller : MaaController [DebuggerBrowsable(DebuggerBrowsableState.Never)] private string DebuggerDisplay => IsInvalid ? $"Invalid {GetType().Name}" - : $"{GetType().Name} {{ {nameof(_debugInfo.Name)} = {_debugInfo.Name}, {nameof(_debugInfo.ClassName)} = {_debugInfo.ClassName}, ScreencapMethod = {_debugInfo.ScreencapMethod}, MouseMethod = {_debugInfo.MouseMethod}, KeyboardMethod = {_debugInfo.KeyboardMethod} }}"; + : $"{GetType().Name} {{ {nameof(_debugInfo.Name)} = {_debugInfo.Name}, {nameof(_debugInfo.ClassName)} = {_debugInfo.ClassName}, ScreencapMethods = {_debugInfo.ScreencapMethods}, MouseMethod = {_debugInfo.MouseMethod}, KeyboardMethod = {_debugInfo.KeyboardMethod} }}"; /// /// Creates a instance. @@ -34,7 +34,7 @@ public MaaWin32Controller(DesktopWindowInfo info, LinkOption link = LinkOption.S ArgumentNullException.ThrowIfNull(info); if (info.Handle == nint.Zero) throw new ArgumentException("Value cannot be zero.", "info.Handle"); - var handle = MaaWin32ControllerCreate(info.Handle, (MaaWin32ScreencapMethod)info.ScreencapMethod, (MaaWin32InputMethod)info.MouseMethod, (MaaWin32InputMethod)info.KeyboardMethod); + var handle = MaaWin32ControllerCreate(info.Handle, (MaaWin32ScreencapMethod)info.ScreencapMethods, (MaaWin32InputMethod)info.MouseMethod, (MaaWin32InputMethod)info.KeyboardMethod); _ = MaaControllerAddSink(handle, MaaEventCallback, (nint)MaaHandleType.Controller); SetHandle(handle, needReleased: true); @@ -45,14 +45,14 @@ public MaaWin32Controller(DesktopWindowInfo info, LinkOption link = LinkOption.S } /// The handle to a win32 window. - /// The screencap method. + /// The screencap methods. /// The mouse method. /// The keyboard method. /// Executes if ; otherwise, not link. /// Checks LinkStart().Wait() status if ; otherwise, not check. /// - public MaaWin32Controller(nint hWnd, Win32ScreencapMethod screencapMethod, Win32InputMethod mouseMethod, Win32InputMethod keyboardMethod, LinkOption link = LinkOption.Start, CheckStatusOption check = CheckStatusOption.ThrowIfNotSucceeded) - : this(new DesktopWindowInfo(hWnd, string.Empty, string.Empty, screencapMethod, mouseMethod, keyboardMethod), link, check) + public MaaWin32Controller(nint hWnd, Win32ScreencapMethods screencapMethods, Win32InputMethod mouseMethod, Win32InputMethod keyboardMethod, LinkOption link = LinkOption.Start, CheckStatusOption check = CheckStatusOption.ThrowIfNotSucceeded) + : this(new DesktopWindowInfo(hWnd, string.Empty, string.Empty, screencapMethods, mouseMethod, keyboardMethod), link, check) { } } diff --git a/src/MaaFramework.Binding.UnitTests/Test_IMaaController.cs b/src/MaaFramework.Binding.UnitTests/Test_IMaaController.cs index 0c755a4..61a94d7 100644 --- a/src/MaaFramework.Binding.UnitTests/Test_IMaaController.cs +++ b/src/MaaFramework.Binding.UnitTests/Test_IMaaController.cs @@ -118,18 +118,18 @@ public void CreateInstances() using var win32Native1 = new MaaWin32Controller( windowInfo.Handle, - Win32ScreencapMethod.GDI, + Win32ScreencapMethods.GDI, Win32InputMethod.SendMessage, Win32InputMethod.SendMessage); using var win32Native2 = new MaaWin32Controller( windowInfo.Handle, - Win32ScreencapMethod.GDI, + Win32ScreencapMethods.GDI, Win32InputMethod.SendMessage, Win32InputMethod.SendMessage, LinkOption.None); using var win32Native3 = new MaaWin32Controller( windowInfo.Handle, - Win32ScreencapMethod.GDI, + Win32ScreencapMethods.GDI, Win32InputMethod.SendMessage, Win32InputMethod.SendMessage, LinkOption.Start, diff --git a/src/MaaFramework.Binding.UnitTests/Test_IMaaToolkit.cs b/src/MaaFramework.Binding.UnitTests/Test_IMaaToolkit.cs index c3afd0f..c4531eb 100644 --- a/src/MaaFramework.Binding.UnitTests/Test_IMaaToolkit.cs +++ b/src/MaaFramework.Binding.UnitTests/Test_IMaaToolkit.cs @@ -103,7 +103,7 @@ private static void Test_Win32_WindowInfos(MaaTypes type, IList windows[0].ToWin32ControllerWith( - screencapMethod: Win32ScreencapMethod.GDI, + screencapMethods: Win32ScreencapMethods.GDI, mouseMethod: Win32InputMethod.SendMessage, keyboardMethod: Win32InputMethod.SendMessage, link: LinkOption.None), @@ -118,7 +118,7 @@ private static void Test_Win32_WindowInfos(MaaTypes type, IList windows[0].ToWin32ControllerWith( - screencapMethod: Win32ScreencapMethod.GDI, + screencapMethods: Win32ScreencapMethods.GDI, mouseMethod: Win32InputMethod.SendMessage, keyboardMethod: Win32InputMethod.SendMessage), _ => throw new NotImplementedException(), diff --git a/src/MaaFramework.Binding/Enums/Controllers/Win32ScreencapMethod.cs b/src/MaaFramework.Binding/Enums/Controllers/Win32ScreencapMethod.cs deleted file mode 100644 index 0995c18..0000000 --- a/src/MaaFramework.Binding/Enums/Controllers/Win32ScreencapMethod.cs +++ /dev/null @@ -1,43 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable CS1573 // 参数在 XML 注释中没有匹配的 param 标记 -#pragma warning disable CS1591 // 缺少对公共可见类型或成员的 XML 注释 - -namespace MaaFramework.Binding; - -/// -/// Win32 screencap method -/// No bitwise OR, select ONE method only. -/// No default value. Client should choose one as default. -/// Different applications use different rendering methods, there is no universal solution. -/// | Method | Speed | Compatibility | Require Admin | Background Support | Notes | -/// |-------------------------|-----------|---------------|---------------|--------------------|----------------------------------| -/// | GDI | Fast | Medium | No | No | | -/// | FramePool | Very Fast | Medium | No | Yes | Requires Windows 10 1903+ | -/// | DXGI_DesktopDup | Very Fast | Low | No | No | Desktop duplication (full screen)| -/// | DXGI_DesktopDup_Window | Very Fast | Low | No | No | Desktop duplication then crop | -/// | PrintWindow | Medium | Medium | No | Yes | | -/// | ScreenDC | Fast | High | No | No | | -/// Note: FramePool and PrintWindow support pseudo-minimize — when the target window -/// is minimized, they make it transparent and click-through, then restore it without -/// activation, allowing screencap to continue without disturbing the user. -/// Other screencap methods will fail when the target window is minimized. -/// -public enum Win32ScreencapMethod : System.UInt64 -{ - None = 0, - GDI = 1, - FramePool = (1 << 1), - DXGI_DesktopDup = (1 << 2), - DXGI_DesktopDup_Window = (1 << 3), - PrintWindow = (1 << 4), - ScreenDC = (1 << 5), -} - diff --git a/src/MaaFramework.Binding/Enums/Controllers/Win32ScreencapMethods.cs b/src/MaaFramework.Binding/Enums/Controllers/Win32ScreencapMethods.cs new file mode 100644 index 0000000..2617a7a --- /dev/null +++ b/src/MaaFramework.Binding/Enums/Controllers/Win32ScreencapMethods.cs @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable CS1573 // 参数在 XML 注释中没有匹配的 param 标记 +#pragma warning disable CS1591 // 缺少对公共可见类型或成员的 XML 注释 + +namespace MaaFramework.Binding; + +/// +/// Win32 screencap method flags +/// +/// Use bitwise OR to set the methods you need. +///
MaaFramework will test all provided methods and use the fastest available one.
+/// +/// No default value. Client should choose one as default. +/// +/// Predefined combinations: +///
- Foreground: DXGI_DesktopDup_Window | ScreenDC +///
- Background: FramePool | PrintWindow
+/// +/// Different applications use different rendering methods, there is no universal solution. +/// +/// | Method | Speed | Compatibility | Require Admin | Background Support | Notes | +///
|-------------------------|-----------|---------------|---------------|--------------------|----------------------------------| +///
| GDI | Fast | Medium | No | No | | +///
| FramePool | Very Fast | Medium | No | Yes | Requires Windows 10 1903+ | +///
| DXGI_DesktopDup | Very Fast | Low | No | No | Desktop duplication (full screen)| +///
| DXGI_DesktopDup_Window | Very Fast | Low | No | No | Desktop duplication then crop | +///
| PrintWindow | Medium | Medium | No | Yes | | +///
| ScreenDC | Fast | High | No | No | | +///
+/// +/// Note: FramePool and PrintWindow support pseudo-minimize — when the target window +///
is minimized, they make it transparent and click-through, then restore it without +///
activation, allowing screencap to continue without disturbing the user. +///
Other screencap methods will fail when the target window is minimized.
+/// +///
+[Flags] +public enum Win32ScreencapMethods : System.UInt64 +{ + None = 0, + GDI = 1, + FramePool = (1 << 1), + DXGI_DesktopDup = (1 << 2), + DXGI_DesktopDup_Window = (1 << 3), + PrintWindow = (1 << 4), + ScreenDC = (1 << 5), + + All = ~None, + Foreground = DXGI_DesktopDup_Window | ScreenDC, + Background = FramePool | PrintWindow, +} + diff --git a/src/MaaFramework.Binding/Infos/DesktopWindowInfo.cs b/src/MaaFramework.Binding/Infos/DesktopWindowInfo.cs index f038d9b..705344f 100644 --- a/src/MaaFramework.Binding/Infos/DesktopWindowInfo.cs +++ b/src/MaaFramework.Binding/Infos/DesktopWindowInfo.cs @@ -6,14 +6,14 @@ /// Gets the handle to a window. /// Gets the window name. /// Gets the window class name. -/// The screencap method. +/// The screencap methods. /// The mouse method. /// The keyboard method. public record DesktopWindowInfo( nint Handle, string Name, string ClassName, - Win32ScreencapMethod ScreencapMethod = Win32ScreencapMethod.DXGI_DesktopDup, + Win32ScreencapMethods ScreencapMethods = Win32ScreencapMethods.Background, Win32InputMethod MouseMethod = Win32InputMethod.Seize, Win32InputMethod KeyboardMethod = Win32InputMethod.Seize );