XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEExtension.NetCore.InputSimulator

【DLL】XFE各类拓展的模拟键盘输入

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFEExtension.NetCore.InputSimulator

add-新增获取窗口的缩放倍率方法

84287ad
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

3 个文件 +23 -4
Modified XFEExtension.NetCore.InputSimulator/InputSimulator.cs +20 -2
@@ -18,9 +18,15 @@ public static partial class InputSimulator
18 18 private static partial int GetSystemMetrics(int nIndex);
19 19 [LibraryImport("user32.dll")]
20 20 private static partial void SetCursorPos(int x, int y);
21 [DllImport("user32.dll")]
21 [LibraryImport("user32.dll")]
22 22 [return: MarshalAs(UnmanagedType.Bool)]
23 private static extern bool GetCursorPos(out Point lpPoint);
23 private static partial bool GetCursorPos(out Point lpPoint);
24 [LibraryImport("user32.dll")]
25 private static partial IntPtr GetDC(IntPtr hWnd);
26 [LibraryImport("user32.dll")]
27 private static partial int ReleaseDC(IntPtr hWnd, IntPtr hDC);
28 [LibraryImport("user32.dll")]
29 private static partial int GetDpiForWindow(IntPtr hWnd);
24 30 #endregion
25 31 #region 常量
26 32 private const int KEYEVENTF_KEYDOWN = 0x0000; // 按键按下
@@ -303,5 +309,17 @@ public static partial class InputSimulator
303 309 GetCursorPos(out Point point);
304 310 return ((double)point.X / (GetSystemMetrics(SM_CXSCREEN) - 1), (double)point.Y / (GetSystemMetrics(SM_CYSCREEN) - 1));
305 311 }
312 /// <summary>
313 /// 获取当前窗口的缩放倍率
314 /// </summary>
315 /// <param name="hWnd">窗口句柄</param>
316 /// <returns></returns>
317 public static double GetScalingFactorForWindow(nint hWnd)
318 {
319 var hDC = GetDC(hWnd);
320 var dpi = GetDpiForWindow(hWnd);
321 ReleaseDC(hWnd, hDC);
322 return dpi / 96.0f;
323 }
306 324 #endregion
307 325 }
Added XFEExtension.NetCore.InputSimulator/Properties/AssemblyInfo.cs +1 -0
@@ -0,0 +1 @@
1 [assembly: System.Runtime.CompilerServices.DisableRuntimeMarshalling]
Modified XFEExtension.NetCore.InputSimulator/XFEExtension.NetCore.InputSimulator.csproj +2 -2
@@ -18,10 +18,10 @@
18 18 <PackageReadmeFile>README.md</PackageReadmeFile>
19 19 <RepositoryUrl>https://github.com/XFEstudio/XFEExtension.NetCore.InputSimulator</RepositoryUrl>
20 20 <PackageTags>XFE;拓展;键盘;按键;模拟输入;Input</PackageTags>
21 <PackageReleaseNotes>修复了不能输入大小写字母的问题</PackageReleaseNotes>
21 <PackageReleaseNotes>新增获取窗口的缩放倍率方法</PackageReleaseNotes>
22 22 <PackageLicenseFile>LICENSE</PackageLicenseFile>
23 23 <PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
24 <Version>2.0.0</Version>
24 <Version>2.1.0</Version>
25 25 <PackageIcon>logoIcon.png</PackageIcon>
26 26 </PropertyGroup>
27 27