Example #1
0
        /// <summary>
        /// Simulate touch drag in one step.
        /// </summary>
        /// <param name="from">The start position.</param>
        /// <param name="to">The end position.</param>
        public static void Drag(Point from, Point to)
        {
            using (Down(from))
            {
                contacts[0].PointerInfo.PointerFlags    = POINTER_FLAG.UPDATE | POINTER_FLAG.INRANGE | POINTER_FLAG.INCONTACT;
                contacts[0].PointerInfo.PtPixelLocation = POINT.Create(to);

                if (!User32.InjectTouchInput(1, contacts))
                {
                    throw new Win32Exception();
                }
            }
        }
Example #2
0
        /// <summary>
        /// Simulate touch drag.
        /// Call <see cref="Down"/> 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 == null ||
                contacts.Length != 1)
            {
                throw new UiAutomationException("Call Touch.Down first.");
            }

            contacts[0].PointerInfo.PointerFlags    = POINTER_FLAG.UPDATE | POINTER_FLAG.INRANGE | POINTER_FLAG.INCONTACT;
            contacts[0].PointerInfo.PtPixelLocation = POINT.Create(position);

            if (!User32.InjectTouchInput(1, contacts))
            {
                throw new Win32Exception();
            }
        }
        /// <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.Create(Position);

            // Check if the position is the same as with last click
            if (lastClick is ButtonClick buttonClick &&
                buttonClick.Button == mouseButton &&
                buttonClick.Position.X == position.X &&
                buttonClick.Position.Y == position.Y)
            {
                // Get the timeout needed to not fire a double click
                var timeout = CurrentDoubleClickTime - 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);
        }