If I know an X and Y coordinate, is there a Windows API or some technique in .Net that I can use to cause the mouse pointer to move to that point?
I know there must be something because there are tools that seem to jump the mouse. But I don’t know if those APIs are easily accessible in .Net. Is there?
Please assume WPF, .Net, and Windows (of course).
Solution
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);
}
Declare import like this:
And use like this: