你能强制移动鼠标吗?

3
如果我知道X和Y坐标,是否有Windows API或.NET中的某种技术可以使鼠标指针移动到该点?我知道肯定有这样的东西,因为有些工具似乎可以跳过鼠标。但我不知道这些API在.NET中是否容易访问。有吗?请假定WPF、.Net和Windows(当然)。
public Window1()  
{  
    InitializeComponent();  
    NativeMethods.SetCursorPos(300, 300);  
}  
public partial class NativeMethods  
{  
    [System.Runtime.InteropServices.DllImportAttribute("user32.dll", 
        EntryPoint = "SetCursorPos")]  
    [return: System.Runtime.InteropServices.MarshalAsAttribute
        (System.Runtime.InteropServices.UnmanagedType.Bool)]  
    public static extern bool SetCursorPos(int X, int Y);  
} 
3个回答

2

像这样声明导入:

[DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y);

使用方法如下:

SetCursorPos(x, y);


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接