public static SendMouseInput ( double x, double y, int data, SendMouseInputFlags flags ) : void | ||
x | double | x coordinate of pointer, if Move flag specified |
y | double | y coordinate of pointer, if Move flag specified |
data | int | wheel movement, or mouse X button, depending on flags |
flags | SendMouseInputFlags | flags to indicate which type of input occurred - move, button press/release, wheel move, etc. |
return | void |
/// <summary> /// Move the mouse to a point and click. The primary mouse button will be used /// this is usually the left button except if the mouse buttons are swaped. /// </summary> /// <param name="pt">The point to click at</param> /// <remarks>pt are in pixels that are relative to desktop origin.</remarks> /// /// <outside_see conditional="false"> /// This API does not work inside the secure execution environment. /// <exception cref="System.Security.Permissions.SecurityPermission"/> /// </outside_see> public static void MoveToAndClick(Point pt) { Input.SendMouseInput(pt.X, pt.Y, 0, SendMouseInputFlags.Move | SendMouseInputFlags.Absolute); // send SendMouseInput works in term of the phisical mouse buttons, therefore we need // to check to see if the mouse buttons are swapped because this method need to use the primary // mouse button. if (SafeNativeMethods.GetSystemMetrics(SafeNativeMethods.SM_SWAPBUTTON) == 0) { // the mouse buttons are not swaped the primary is the left Input.SendMouseInput(pt.X, pt.Y, 0, SendMouseInputFlags.LeftDown | SendMouseInputFlags.Absolute); Input.SendMouseInput(pt.X, pt.Y, 0, SendMouseInputFlags.LeftUp | SendMouseInputFlags.Absolute); } else { // the mouse buttons are swaped so click the right button which as actually the primary Input.SendMouseInput(pt.X, pt.Y, 0, SendMouseInputFlags.RightDown | SendMouseInputFlags.Absolute); Input.SendMouseInput(pt.X, pt.Y, 0, SendMouseInputFlags.RightUp | SendMouseInputFlags.Absolute); } }
/// <summary> /// Move the mouse to a point. /// </summary> /// <param name="pt">The point that the mouse will move to.</param> /// <remarks>pt are in pixels that are relative to desktop origin.</remarks> /// /// <outside_see conditional="false"> /// This API does not work inside the secure execution environment. /// <exception cref="System.Security.Permissions.SecurityPermission"/> /// </outside_see> public static void MoveTo(Point pt) { Input.SendMouseInput(pt.X, pt.Y, 0, SendMouseInputFlags.Move | SendMouseInputFlags.Absolute); }