/// <summary> /// Clicks the specified mouse button at the current location. /// </summary> /// <param name="mouseButton">The mouse button to click.</param> public static void Click(MouseButton mouseButton) { var position = POINT.From(Position); if (lastClick is { } buttonClick&& buttonClick.Button == mouseButton && Math.Abs(buttonClick.Point.X - position.X) < User32.GetSystemMetrics(SystemMetric.SM_CXDOUBLECLK) / 2 && Math.Abs(buttonClick.Point.Y - position.Y) < User32.GetSystemMetrics(SystemMetric.SM_CYDOUBLECLK) / 2) { // Get the timeout needed to not fire a double click var timeout = User32.GetDoubleClickTime() - DateTime.UtcNow.Subtract(buttonClick.Time).Milliseconds; // Wait the needed time to prevent the double click if (timeout > 0) { Wait.For(TimeSpan.FromMilliseconds(timeout + ExtraMillisecondsBecauseOfBugInWindows)); } } Down(mouseButton); Up(mouseButton); lastClick = new ButtonClick(mouseButton, position); Wait.UntilInputIsProcessed(); }
/// <summary> /// Create an instance of the class. /// </summary> /// <param name="from">The start position.</param> /// <param name="to">The end position.</param> /// <param name="time">The total time of the interpolation.</param> public static Interpolation Start(Point from, Point to, TimeSpan time) => new Interpolation(POINT.From(from), POINT.From(to), time);
/// <summary> /// Create an instance of <see cref="Interpolation"/>. /// </summary> /// <param name="from">The start position.</param> /// <param name="to">The end position.</param> /// <param name="speed">The speed in pixels / s.</param> /// <returns>An instance of <see cref="Interpolation"/>.</returns> public static Interpolation Start(Point from, Point to, double speed) => Start(POINT.From(from), POINT.From(to), speed);
/// <summary> /// Simulate touch drag. /// Call <see cref="Hold(Point)"/> before calling this method. /// This method is useful when dragging to multiple positions. /// </summary> /// <param name="position">The position.</param> public static void DragTo(Point position) { if (contacts is null || contacts.Length != 1) { throw new UiAutomationException("Call Touch.Down first."); } var interpolation = Interpolation.Start(contacts[0].PointerInfo.PtPixelLocation, POINT.From(position), MoveSpeed); while (interpolation.TryGetPosition(out var pos)) { contacts[0].PointerInfo.PointerFlags = POINTER_FLAG.UPDATE | POINTER_FLAG.INRANGE | POINTER_FLAG.INCONTACT; contacts[0].PointerInfo.PtPixelLocation = pos; if (!User32.InjectTouchInput(1, contacts)) { throw new Win32Exception(); } Wait.For(TimeSpan.FromMilliseconds(10)); } }