public static void DragToTarget(UIObject obj, UIObject obj2) { Point startPoint = obj.GetClickablePoint(); Log.Comment("Start Point X:{0} Y:{1}", startPoint.X, startPoint.Y); Point end = obj2.GetClickablePoint(); Log.Comment("End Point X:{0} Y:{1}", end.X, end.Y); uint dragDuration = 2000; using (var waiter = GetWaiterForInputEvent(obj, InputEvent.Drag)) { if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5)) { Log.Warning("Touch input is not available on OS versions less than RS5. Falling back to mouse input."); Log.Comment("Move input to Start Point."); PointerInput.Move(startPoint); Log.Comment("Begin Drag."); PointerInput.ClickDrag(end, PointerButtons.Primary, dragDuration); Log.Comment("Drag Complete."); } else { Log.Comment("Move input to Start Point."); SinglePointGesture.Current.Move(startPoint); Log.Comment("Begin Drag."); SinglePointGesture.Current.PressAndDrag(end, dragDuration, 500); Log.Comment("Drag Complete."); } } Wait.ForIdle(); }
public static void Pan(UIObject obj, Point start, Point end, uint holdDuration = DefaultPanHoldDuration, float panAcceleration = DefaultPanAcceleration, uint dragDuration = DefaultDragDuration, bool waitForIdle = true) { Log.Comment("Pan on {0}, starting at ({1}, {2}), ending at ({3}, {4}), after holding {5} ms, with acceleration {6}.", obj.GetIdentifier(), start.X, start.Y, end.X, end.Y, holdDuration, panAcceleration); if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5)) { using (var waiter = GetWaiterForInputEvent(obj, InputEvent.Drag)) { Log.Warning("Touch input is not available on OS versions less than RS5. Falling back to mouse input."); PointerInput.Move(start); PointerInput.ClickDrag(end, PointerButtons.Primary, dragDuration); } } else { if (panAcceleration == 0.0f) { using (var waiter = GetWaiterForInputEvent(obj, InputEvent.Drag)) { SinglePointGesture.Current.Move(start); SinglePointGesture.Current.PressAndDrag(end, dragDuration, holdDuration); } } else { using (var waiter = GetWaiterForInputEvent(obj, InputEvent.Pan)) { SinglePointGesture.Current.Move(start); SinglePointGesture.Current.Pan(end, holdDuration, panAcceleration); } } } if (waitForIdle) { Wait.ForIdle(); } }
public static void DragDistance(UIObject obj, int distance, Direction direction, uint duration = 4000) { Log.Comment("Drag {0} {1} pixels in the {2} direction.", obj.GetIdentifier(), distance, direction); Point startPoint = obj.GetClickablePoint(); double directionRadians = DirectionToAngle(direction) * Math.PI / 180d; Log.Comment("Start Point X:{0} Y:{1}", startPoint.X, startPoint.Y); Point end = new Point() { X = startPoint.X + (int)Math.Round(distance * Math.Cos(directionRadians)), Y = startPoint.Y - (int)Math.Round(distance * Math.Sin(directionRadians)) }; Log.Comment("End Point X:{0} Y:{1}", end.X, end.Y); using (var waiter = GetWaiterForInputEvent(obj, InputEvent.Drag)) { if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5)) { Log.Warning("Touch input is not available on OS versions less than RS5. Falling back to mouse input."); Log.Comment("Move input to Start Point."); PointerInput.Move(startPoint); Log.Comment("Begin Drag."); PointerInput.ClickDrag(end, PointerButtons.Primary, duration); Log.Comment("Drag Complete."); } else { Log.Comment("Move input to Start Point."); SinglePointGesture.Current.Move(startPoint); Log.Comment("Begin Drag."); SinglePointGesture.Current.ClickDrag(end, PointerButtons.Primary, duration); Log.Comment("Drag Complete."); } } Wait.ForIdle(); }