private static void MouseEvent(NativeMethods.MOUSEEVENTF evt, double x, double y) { NativeMethods.InputUnion[] input = new NativeMethods.InputUnion[1]; input[0] = new NativeMethods.InputUnion() { mi = new NativeMethods.MOUSEINPUT() { dwFlags = evt, dx = (int)x, dy = (int)y, } }; uint res = NativeMethods.SendInput(1, input, Marshal.SizeOf(input)); }
private static void DoMouse(NativeMethods.MOUSEEVENTF flags, Point newPoint, int scrollSize = 0) { NativeMethods.INPUT input = new NativeMethods.INPUT(); NativeMethods.MOUSEINPUT mi = new NativeMethods.MOUSEINPUT(); input.dwType = NativeMethods.InputType.Mouse; input.mi = mi; input.mi.dwExtraInfo = IntPtr.Zero; // mouse co-ords: top left is (0,0), bottom right is (65535, 65535) // convert screen co-ord to mouse co-ords... input.mi.dx = newPoint.X * 65535 / Screen.PrimaryScreen.Bounds.Width; input.mi.dy = newPoint.Y * 65535 / Screen.PrimaryScreen.Bounds.Height; input.mi.time = 0; input.mi.mouseData = scrollSize * 120; // can be used for WHEEL event see msdn input.mi.dwFlags = flags; int cbSize = Marshal.SizeOf(typeof(NativeMethods.INPUT)); int result = NativeMethods.SendInput(1, ref input, cbSize); // if ( result == 0 ) // Debug.WriteLine( Marshal.GetLastWin32Error() ); }
public static uint MouseEvent(NativeMethods.MOUSEEVENTF evt, double x, double y) { NativeMethods.InputUnion[] input = { new NativeMethods.InputUnion { type = 0, mi = new NativeMethods.MOUSEINPUT { dwFlags = evt, dx = (int)x, dy = (int)y, time = 0, mouseData = 0, dwExtraInfo = UIntPtr.Zero } } }; return(NativeMethods.SendInput((uint)input.Length, input, Marshal.SizeOf <NativeMethods.InputUnion>())); }