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

XFEExtension.NetCore.InputSimulator

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

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

XFEstudio/XFEExtension.NetCore.InputSimulator

修复部分bug

64f87dd
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

2 个文件 +97 -2
Modified XFE各类拓展.NetCore.InputSimulator/InputSimulator.cs +53 -2
@@ -16,10 +16,10 @@ public static partial class InputSimulator
16 16 [LibraryImport("user32.dll")]
17 17 private static partial int GetSystemMetrics(int nIndex);
18 18 [LibraryImport("user32.dll")]
19 static partial void SetCursorPos(int x, int y);
19 private static partial void SetCursorPos(int x, int y);
20 20 [DllImport("user32.dll")]
21 21 [return: MarshalAs(UnmanagedType.Bool)]
22 static extern bool GetCursorPos(out Point lpPoint);
22 private static extern bool GetCursorPos(out Point lpPoint);
23 23 #endregion
24 24 #region 常量
25 25 private const int KEYEVENTF_KEYDOWN = 0x0000; // 按键按下
@@ -136,6 +136,48 @@ public static partial class InputSimulator
136 136 LocateTo(point.X, point.Y);
137 137 }
138 138 /// <summary>
139 /// 将鼠标定位至
140 /// </summary>
141 /// <remarks>
142 /// 如果需要相对移动请使用<see cref="Move(int, int)"/>方法
143 /// </remarks>
144 /// <param name="screenPosition">屏幕空间位置</param>
145 public static void LocateTo(ScreenPosition screenPosition)
146 {
147 switch (screenPosition)
148 {
149 case ScreenPosition.TopLeft:
150 LocateTo(0, 0);
151 break;
152 case ScreenPosition.TopRight:
153 LocateTo(GetScreenSize().X - 1, 0);
154 break;
155 case ScreenPosition.Top:
156 LocateTo(GetScreenSize().X / 2, 0);
157 break;
158 case ScreenPosition.Left:
159 LocateTo(0, GetScreenSize().Y / 2);
160 break;
161 case ScreenPosition.Right:
162 LocateTo(GetScreenSize().X - 1, GetScreenSize().Y / 2);
163 break;
164 case ScreenPosition.Center:
165 LocateTo(GetScreenSize().X / 2, GetScreenSize().Y / 2);
166 break;
167 case ScreenPosition.BottomLeft:
168 LocateTo(0, GetScreenSize().Y - 1);
169 break;
170 case ScreenPosition.Bottom:
171 LocateTo(GetScreenSize().X / 2, GetScreenSize().Y - 1);
172 break;
173 case ScreenPosition.BottomRight:
174 LocateTo(GetScreenSize().X - 1, GetScreenSize().Y - 1);
175 break;
176 default:
177 break;
178 }
179 }
180 /// <summary>
139 181 /// 模拟鼠标点击
140 182 /// </summary>
141 183 /// <param name="mouseButton">鼠标按键</param>
@@ -206,5 +248,14 @@ public static partial class InputSimulator
206 248 GetCursorPos(out Point point);
207 249 return point;
208 250 }
251 /// <summary>
252 /// 获取鼠标位置相对于屏幕大小的百分比
253 /// </summary>
254 /// <returns>百分比,0-1之间(X, Y)</returns>
255 public static (double X, double Y) GetMousePointRelatively()
256 {
257 GetCursorPos(out Point point);
258 return ((double)point.X / GetSystemMetrics(SM_CXSCREEN), (double)point.Y / GetSystemMetrics(SM_CYSCREEN));
259 }
209 260 #endregion
210 261 }
Added XFE各类拓展.NetCore.InputSimulator/ScreenPosition.cs +44 -0
@@ -0,0 +1,44 @@
1 namespace XFE各类拓展.NetCore.InputSimulator;
2
3 /// <summary>
4 /// 屏幕位置
5 /// </summary>
6 public enum ScreenPosition
7 {
8 /// <summary>
9 /// 左上角
10 /// </summary>
11 TopLeft,
12 /// <summary>
13 /// 右上角
14 /// </summary>
15 TopRight,
16 /// <summary>
17 /// 上方
18 /// </summary>
19 Top,
20 /// <summary>
21 /// 左边
22 /// </summary>
23 Left,
24 /// <summary>
25 /// 右边
26 /// </summary>
27 Right,
28 /// <summary>
29 /// 中心
30 /// </summary>
31 Center,
32 /// <summary>
33 /// 左下角
34 /// </summary>
35 BottomLeft,
36 /// <summary>
37 /// 下方
38 /// </summary>
39 Bottom,
40 /// <summary>
41 /// 右下角
42 /// </summary>
43 BottomRight
44 }