/// <summary>
/// 引用user32.dll动态链接库(windows api),
/// 使用库中定义 API:SetCursorPos
/// </summary>
[DllImport("user32.dll")]
private static extern int SetCursorPos(int x, int y);
/// <summary>
/// 移动鼠标到指定的坐标点
/// </summary>
public void MoveMouseToPoint(Point p)
{
SetCursorPos(p.X, p.Y);
}
/// <summary>
/// 设置鼠标的移动范围
/// </summary>
public void SetMouseRectangle(Rectangle rectangle)
{
System.Windows.Forms.Cursor.Clip = rectangle;
}
/// <summary>
/// 设置鼠标位于屏幕中心
/// </summary>
public void SetMouseAtCenterScreen()
{
int winHeight = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
int winWidth = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
Point centerP = new Point(0, 0);
MoveMouseToPoint(centerP);
}
相关文章
- 【转载】C#中List集合使用AddRange方法将一个集合加入到指定集合末尾
- Mac操作:Mac系统移动鼠标显示桌面(移动鼠标到角落)
- X64Dbg软件--常用调试技巧--查找系统函数调用位置--执行到指定位置断点
- 用Qt5.9Creator获取鼠标位置和用键盘移动按钮例子
- c#利用winAPI;修改窗口位置,移动窗口,修改标题/名称,模拟鼠标键盘。配合按键精灵或者自己写操作,结合起来使用能节约不少时间。真香。
- 鼠标画框,改变框的大小,方向键移动框的位置
- WPF C# 多屏情况下,实现窗体显示到指定的屏幕内
- Unity 背包系统中拖拽物体到指定位置或互换位置效果的实现
- C# WinForm开发系列之chart控件画折线图和柱形图并自定义鼠标移动到数据标记点显示提示信息
- Powershell管理系列(二十九)PowerShell操作之移动账户到指定OU