示例#1
0
        private static void ScrollToTop()
        {
            sm_log.Info("Scrolling sidebar to top");

            var       sidebarRect   = new Rectangle(ScreenCapture.ScreenBounds.Location, new Size(ScreenLayout.SidebarWidth, SidebarUtil.MaxHeight));
            const int maxIterations = 100;

            for (int i = 0; i < maxIterations; i++)
            {
                // Drag upwards as much as we can
                MouseUtils.RightDrag(sidebarRect.Location, new Point(sidebarRect.Left, ScreenCapture.ScreenBounds.Height - 1));

                // To check if we've reached the top, try to drag upwards one more pixel. If nothing changes,
                // we're almost definitely at the top!
                using (var capture1 = new ScreenCapture(sidebarRect))
                {
                    MouseUtils.RightDrag(sidebarRect.Location, sidebarRect.Location.Add(new Point(0, 1)));
                    using (var capture2 = new ScreenCapture(sidebarRect))
                    {
                        if (BitmapComparer.AreBitmapsIdentical(capture1.Bitmap, capture2.Bitmap))
                        {
                            return;
                        }
                    }
                }
            }

            throw new AnalysisException(Invariant($"Failed to scroll to the top of the sidebar after {maxIterations} attempts."));
        }
示例#2
0
        private bool DragAreaWithVerticalCheck(Point start, Point end)
        {
            using (var capture1 = new ScreenCapture(VerticalCheckRect.Value))
            {
                MouseUtils.RightDrag(start, end, ScrollDelay);
                using (var capture2 = new ScreenCapture(VerticalCheckRect.Value))
                {
                    if (!BitmapComparer.AreBitmapsIdentical(capture1.Bitmap, capture2.Bitmap))
                    {
                        sm_log.Info("Drag successful");
                        return(true);
                    }

                    sm_log.Warn(Invariant($"Attempted to drag from {start} to {end} but detected no vertical movement. Waiting a little while before checking again..."));
                    ThreadUtils.SleepOrAbort(100 + ScrollDelay);

                    using (var capture3 = new ScreenCapture(VerticalCheckRect.Value))
                    {
                        if (!BitmapComparer.AreBitmapsIdentical(capture1.Bitmap, capture3.Bitmap))
                        {
                            sm_log.Info("Drag successful");
                            return(true);
                        }

                        sm_log.Warn("Still no vertical movement detected");
                        return(false);
                    }
                }
            }
        }