コード例 #1
0
        /// <summary>
        /// Look for a widget with the given name and click it. It and all its parents must be visible and enabled.
        /// </summary>
        /// <param name="widgetName">The given widget name</param>
        /// <param name="secondsToWait">Total seconds to stay in this function waiting for the named widget to become visible.</param>
        public void ClickByName(string widgetName, SearchRegion searchRegion = null, Point2D offset = default(Point2D), ClickOrigin origin = ClickOrigin.Center, bool isDoubleClick = false)
        {
            double secondsToWait = 5;

            GuiWidget widgetToClick = GetWidgetByName(widgetName, out SystemWindow containingWindow, out Point2D offsetHint, secondsToWait, searchRegion);

            if (widgetToClick != null)
            {
                MoveMouseToWidget(widgetToClick, containingWindow, offset, offsetHint, origin, out Point2D screenPosition);
                inputSystem.CreateMouseEvent(NativeMethods.MOUSEEVENTF_LEFTDOWN, screenPosition.x, screenPosition.y, 0, 0);
                WaitforDraw(containingWindow);

                if (isDoubleClick)
                {
                    Thread.Sleep(150);
                    inputSystem.CreateMouseEvent(NativeMethods.MOUSEEVENTF_LEFTDOWN, screenPosition.x, screenPosition.y, 0, 0);
                    WaitforDraw(containingWindow);
                }

                Delay(UpDelaySeconds);

                inputSystem.CreateMouseEvent(NativeMethods.MOUSEEVENTF_LEFTUP, screenPosition.x, screenPosition.y, 0, 0);

                WaitforDraw(containingWindow);

                Delay(0.2);

                return;
            }

            throw new Exception($"ClickByName Failed: Named GuiWidget not found [{widgetName}]");
        }
コード例 #2
0
        public bool NamedWidgetExists(string widgetName, SearchRegion searchRegion = null, bool onlyVisible = true)
        {
            // Ignore SystemWindows with null PlatformWindow members - SystemWindow constructed but not yet shown
            foreach (SystemWindow window in SystemWindow.AllOpenSystemWindows.ToArray())
            {
                var foundChildren = window.FindDescendants(widgetName);
                if (foundChildren.Count > 0)
                {
                    foreach (GuiWidget.WidgetAndPosition foundChild in foundChildren)
                    {
                        if (onlyVisible)
                        {
                            RectangleDouble childBounds = foundChild.widget.TransformToParentSpace(window, foundChild.widget.LocalBounds);

                            ScreenRectangle screenRect = SystemWindowToScreen(childBounds, window);
                            ScreenRectangle result;
                            if (searchRegion == null ||
                                ScreenRectangle.Intersection(searchRegion.ScreenRect, screenRect, out result))
                            {
                                if (foundChild.widget.ActuallyVisibleOnScreen())
                                {
                                    return(true);
                                }
                            }
                        }
                        else
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
コード例 #3
0
        public bool ImageExists(ImageBuffer imageNeedle, double secondsToWait = 0, SearchRegion searchRegion = null)
        {
            if (secondsToWait > 0)
            {
                bool foundImage = WaitForImage(imageNeedle, secondsToWait, searchRegion);
                if (!foundImage)
                {
                    return(false);
                }
            }

            if (searchRegion == null)
            {
                searchRegion = GetScreenRegion();
            }

            Vector2 matchPosition;
            double  bestMatch;

            if (searchRegion.Image.FindLeastSquaresMatch(imageNeedle, out matchPosition, out bestMatch, MatchLimit))
            {
                return(true);
            }

            return(false);
        }
コード例 #4
0
        public bool WidgetExists <T>(SearchRegion searchRegion = null) where T : GuiWidget
        {
            // Ignore SystemWindows with null PlatformWindow members - SystemWindow constructed but not yet shown
            foreach (SystemWindow window in SystemWindow.AllOpenSystemWindows.ToArray())
            {
                IEnumerable <T> foundChildren = window.Children <T>();
                if (foundChildren.Count() > 0)
                {
                    foreach (var foundChild in foundChildren)
                    {
                        RectangleDouble childBounds = foundChild.TransformToParentSpace(window, foundChild.LocalBounds);

                        ScreenRectangle screenRect = SystemWindowToScreen(childBounds, window);
                        ScreenRectangle result;
                        if (searchRegion == null || ScreenRectangle.Intersection(searchRegion.ScreenRect, screenRect, out result))
                        {
                            if (foundChild.ActuallyVisibleOnScreen())
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
コード例 #5
0
        public bool DropImage(ImageBuffer imageNeedle, double secondsToWait = 0, SearchRegion searchRegion = null, Point2D offset = default(Point2D), ClickOrigin origin = ClickOrigin.Center)
        {
            if (origin == ClickOrigin.Center)
            {
                offset.x += imageNeedle.Width / 2;
                offset.y += imageNeedle.Height / 2;
            }

            if (searchRegion == null)
            {
                searchRegion = GetScreenRegion();
            }

            Vector2 matchPosition;
            double  bestMatch;

            if (searchRegion.Image.FindLeastSquaresMatch(imageNeedle, out matchPosition, out bestMatch, MatchLimit))
            {
                int screenHeight   = inputSystem.GetCurrentScreenHeight();
                int clickY         = (int)(searchRegion.ScreenRect.Bottom + matchPosition.y + offset.y);
                int clickYOnScreen = screenHeight - clickY;                 // invert to put it on the screen

                Point2D screenPosition = new Point2D((int)matchPosition.x + offset.x, clickYOnScreen);
                SetMouseCursorPosition(screenPosition.x, screenPosition.y);
                inputSystem.CreateMouseEvent(NativeMethods.MOUSEEVENTF_LEFTUP, screenPosition.x, screenPosition.y, 0, 0);

                return(true);
            }

            return(false);
        }
コード例 #6
0
        public bool NameExists(string widgetName, SearchRegion searchRegion = null)
        {
            foreach (SystemWindow window in SystemWindow.AllOpenSystemWindows)
            {
                List <GuiWidget> foundChildren = new List <GuiWidget>();
                window.FindNamedChildrenRecursive(widgetName, foundChildren);
                if (foundChildren.Count > 0)
                {
                    foreach (GuiWidget foundChild in foundChildren)
                    {
                        RectangleDouble childBounds = foundChild.TransformToParentSpace(window, foundChild.LocalBounds);

                        ScreenRectangle screenRect = SystemWindowToScreen(childBounds, window);
                        ScreenRectangle result;
                        if (searchRegion == null || ScreenRectangle.Intersection(searchRegion.ScreenRect, screenRect, out result))
                        {
                            if (foundChild.ActuallyVisibleOnScreen())
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
コード例 #7
0
        /// <summary>
        /// Look for a widget with the given name and click it. It and all its parents must be visible and enabled.
        /// </summary>
        /// <param name="widgetName">The given widget name</param>
        /// <param name="secondsToWait">Total seconds to stay in this function waiting for the named widget to become visible.</param>
        public void ClickByName(string widgetName, double secondsToWait = 5, SearchRegion searchRegion = null, Point2D offset = default(Point2D), ClickOrigin origin = ClickOrigin.Center, double delayBeforeReturn = 0.2)
        {
            SystemWindow containingWindow;
            GuiWidget    widgetToClick = GetWidgetByName(widgetName, out containingWindow, secondsToWait, searchRegion);

            if (widgetToClick != null)
            {
                RectangleDouble childBounds = widgetToClick.TransformToParentSpace(containingWindow, widgetToClick.LocalBounds);

                if (origin == ClickOrigin.Center)
                {
                    offset.x += (int)childBounds.Width / 2;
                    offset.y += (int)childBounds.Height / 2;
                }

                Point2D screenPosition = SystemWindowToScreen(new Point2D(childBounds.Left + offset.x, childBounds.Bottom + offset.y), containingWindow);

                SetMouseCursorPosition(screenPosition.x, screenPosition.y);
                inputSystem.CreateMouseEvent(NativeMethods.MOUSEEVENTF_LEFTDOWN, screenPosition.x, screenPosition.y, 0, 0);

                Wait(UpDelaySeconds);

                inputSystem.CreateMouseEvent(NativeMethods.MOUSEEVENTF_LEFTUP, screenPosition.x, screenPosition.y, 0, 0);

                // After firing the click event, wait the given period of time before returning to allow MatterControl
                // to complete the targeted action
                Wait(delayBeforeReturn);

                return;
            }

            throw new Exception($"ClickByName Failed: Named GuiWidget not found [{widgetName}]");
        }
コード例 #8
0
ファイル: AutomationRunner.cs プロジェクト: huhen/agg-sharp
        /// <summary>
        /// Look for a widget with the given name and click it. It and all its parents must be visible and enabled.
        /// </summary>
        /// <param name="widgetName"></param>
        /// <param name="origin"></param>
        /// <param name="secondsToWait">Total seconds to stay in this function waiting for the named widget to become visible.</param>
        /// <returns></returns>
        public bool ClickByName(string widgetName, double secondsToWait = 0, SearchRegion searchRegion = null, Point2D offset = default(Point2D), ClickOrigin origin = ClickOrigin.Center)
        {
            SystemWindow containingWindow;
            GuiWidget    widgetToClick = GetWidgetByName(widgetName, out containingWindow, secondsToWait, searchRegion);

            if (widgetToClick != null)
            {
                RectangleDouble childBounds = widgetToClick.TransformToParentSpace(containingWindow, widgetToClick.LocalBounds);

                if (origin == ClickOrigin.Center)
                {
                    offset.x += (int)childBounds.Width / 2;
                    offset.y += (int)childBounds.Height / 2;
                }

                Point2D screenPosition = SystemWindowToScreen(new Point2D(childBounds.Left + offset.x, childBounds.Bottom + offset.y), containingWindow);

                SetMouseCursorPosition(screenPosition.x, screenPosition.y);
                inputSystem.CreateMouseEvent(NativeMethods.MOUSEEVENTF_LEFTDOWN, screenPosition.x, screenPosition.y, 0, 0);

                Wait(upDelaySeconds);

                inputSystem.CreateMouseEvent(NativeMethods.MOUSEEVENTF_LEFTUP, screenPosition.x, screenPosition.y, 0, 0);

                return(true);
            }

            return(false);
        }
コード例 #9
0
        public bool ChildExists <T>(SearchRegion searchRegion = null) where T : GuiWidget
        {
            // Ignore SystemWindows with null PlatformWindow members - SystemWindow constructed but not yet shown
            foreach (var systemWindow in SystemWindow.AllOpenSystemWindows.ToArray())
            {
                // Get either the topmost or active SystemWindow
                var window = systemWindow.Parents <GuiWidget>().LastOrDefault() as SystemWindow ?? systemWindow;

                // Single window implementation requires both windows to be checked
                var foundChildren = window.Children <T>().Concat(systemWindow.Children <T>());
                if (foundChildren.Count() > 0)
                {
                    foreach (var foundChild in foundChildren)
                    {
                        RectangleDouble childBounds = foundChild.TransformToParentSpace(window, foundChild.LocalBounds);

                        ScreenRectangle screenRect = SystemWindowToScreen(childBounds, window);
                        ScreenRectangle result;
                        if (searchRegion == null || ScreenRectangle.Intersection(searchRegion.ScreenRect, screenRect, out result))
                        {
                            if (foundChild.ActuallyVisibleOnScreen())
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
コード例 #10
0
        public bool DropImage(string imageName, double secondsToWait = 0, SearchRegion searchRegion = null, Point2D offset = default(Point2D), ClickOrigin origin = ClickOrigin.Center)
        {
            ImageBuffer imageToLookFor = LoadImageFromSourceFolder(imageName);

            if (imageToLookFor != null)
            {
                return(DropImage(imageToLookFor, secondsToWait, searchRegion, offset, origin));
            }

            return(false);
        }
コード例 #11
0
        public bool WaitForImage(string imageName, double secondsToWait, SearchRegion searchRegion = null)
        {
            ImageBuffer imageToLookFor = LoadImageFromSourceFolder(imageName);

            if (imageToLookFor != null)
            {
                return(WaitForImage(imageToLookFor, secondsToWait, searchRegion));
            }

            return(false);
        }
コード例 #12
0
ファイル: AutomationRunner.cs プロジェクト: huhen/agg-sharp
        public bool ClickImage(string imageName, double secondsToWait = 0, SearchRegion searchRegion = null, Point2D offset = default(Point2D), ClickOrigin origin = ClickOrigin.Center, MouseButtons mouseButtons = MouseButtons.Left)
        {
            ImageBuffer imageToLookFor = LoadImageFromSourcFolder(imageName);

            if (imageToLookFor != null)
            {
                return(ClickImage(imageToLookFor, secondsToWait, searchRegion, offset, origin, mouseButtons));
            }

            return(false);
        }
コード例 #13
0
        /// <summary>
        /// Look for a widget with the given name and click it. It and all its parents must be visible and enabled.
        /// </summary>
        /// <param name="widgetName">The given widget name</param>
        /// <param name="secondsToWait">Total seconds to stay in this function waiting for the named widget to become visible.</param>
        public void ClickByName(string widgetName, SearchRegion searchRegion = null, Point2D offset = default(Point2D), ClickOrigin origin = ClickOrigin.Center, bool isDoubleClick = false)
        {
            double secondsToWait = 5;

            GuiWidget widgetToClick = GetWidgetByName(widgetName, out SystemWindow containingWindow, out Point2D offsetHint, secondsToWait, searchRegion);

            if (widgetToClick != null)
            {
                this.ClickWidget(widgetToClick, containingWindow, origin, offset, offsetHint, isDoubleClick);

                return;
            }

            throw new Exception($"ClickByName Failed: Named GuiWidget not found [{widgetName}]");
        }
コード例 #14
0
        public bool NameExists(string widgetName, SearchRegion searchRegion = null)
        {
            foreach (SystemWindow window in SystemWindow.OpenWindows)
            {
                GuiWidget widgetToClick = window.FindNamedChildRecursive(widgetName);
                if (widgetToClick != null)
                {
                    if (widgetToClick.ActuallyVisibleOnScreen())
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
コード例 #15
0
        public bool DragDropImage(ImageBuffer imageNeedleDrag, ImageBuffer imageNeedleDrop, int xOffsetDrag = 0, int yOffsetDrag = 0, ClickOrigin originDrag = ClickOrigin.Center,
                                  int xOffsetDrop           = 0, int yOffsetDrop = 0, ClickOrigin originDrop = ClickOrigin.Center,
                                  SearchRegion searchRegion = null)
        {
            if (searchRegion == null)
            {
                searchRegion = GetScreenRegion();
            }

            if (DragImage(imageNeedleDrag, xOffsetDrag, yOffsetDrag, originDrag, searchRegion))
            {
                return(DropImage(imageNeedleDrop, xOffsetDrop, yOffsetDrop, originDrop, searchRegion));
            }

            return(false);
        }
コード例 #16
0
        public bool DragDropImage(string imageNameDrag, string imageNameDrop, int xOffsetDrag = 0, int yOffsetDrag = 0, ClickOrigin originDrag = ClickOrigin.Center,
                                  int xOffsetDrop           = 0, int yOffsetDrop = 0, ClickOrigin originDrop = ClickOrigin.Center,
                                  SearchRegion searchRegion = null)
        {
            ImageBuffer imageNeedleDrag = LoadImageFromSourcFolder(imageNameDrag);

            if (imageNeedleDrag != null)
            {
                ImageBuffer imageNeedleDrop = LoadImageFromSourcFolder(imageNameDrop);
                if (imageNeedleDrop != null)
                {
                    return(DragDropImage(imageNeedleDrag, imageNeedleDrop, xOffsetDrag, yOffsetDrag, originDrag, xOffsetDrop, yOffsetDrop, originDrop, searchRegion));
                }
            }

            return(false);
        }
コード例 #17
0
        public bool WaitForImage(ImageBuffer imageNeedle, double secondsToWait, SearchRegion searchRegion = null)
        {
            Stopwatch timeWaited = Stopwatch.StartNew();

            while (!ImageExists(imageNeedle) &&
                   timeWaited.Elapsed.TotalSeconds < secondsToWait)
            {
                Wait(.05);
            }

            if (timeWaited.Elapsed.TotalSeconds > secondsToWait)
            {
                return(false);
            }

            return(true);
        }
コード例 #18
0
ファイル: AutomationRunner.cs プロジェクト: huhen/agg-sharp
        public bool NameExists(string widgetName, SearchRegion searchRegion = null)
        {
            foreach (SystemWindow window in SystemWindow.AllOpenSystemWindows)
            {
                List <GuiWidget> foundChildren = new List <GuiWidget>();
                window.FindNamedChildrenRecursive(widgetName, foundChildren);
                if (foundChildren.Count > 0)
                {
                    foreach (GuiWidget foundChild in foundChildren)
                    {
                        if (foundChild.ActuallyVisibleOnScreen())
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
コード例 #19
0
        public bool MoveToByName(string widgetName, double secondsToWait = 0, SearchRegion searchRegion = null, Point2D offset = default(Point2D), ClickOrigin origin = ClickOrigin.Center)
        {
            SystemWindow containingWindow;
            Point2D      offsetHint;
            GuiWidget    widgetToClick = GetWidgetByName(widgetName, out containingWindow, out offsetHint, secondsToWait, searchRegion);

            if (widgetToClick != null)
            {
                RectangleDouble childBounds = widgetToClick.TransformToParentSpace(containingWindow, widgetToClick.LocalBounds);

                if (origin == ClickOrigin.Center)
                {
                    offset += offsetHint;
                }

                Point2D screenPosition = SystemWindowToScreen(new Point2D(childBounds.Left + offset.x, childBounds.Bottom + offset.y), containingWindow);
                SetMouseCursorPosition(screenPosition.x, screenPosition.y);

                return(true);
            }

            return(false);
        }
コード例 #20
0
        public GuiWidget GetWidgetByName(string widgetName, out SystemWindow containingWindow, double secondsToWait = 0, SearchRegion searchRegion = null)
        {
            containingWindow = null;

            List <GetResults> getResults = GetWidgetsByName(widgetName, secondsToWait, searchRegion);

            if (getResults != null &&
                getResults.Count > 0)
            {
                containingWindow = getResults[0].containingSystemWindow;
                return(getResults[0].widget);
            }

            return(null);
        }
コード例 #21
0
ファイル: AutomationRunner.cs プロジェクト: eriser/agg-sharp
		public bool DropImage(string imageName, double secondsToWait = 0, SearchRegion searchRegion = null, Point2D offset = default(Point2D), ClickOrigin origin = ClickOrigin.Center)
		{
			ImageBuffer imageToLookFor = LoadImageFromSourcFolder(imageName);
			if (imageToLookFor != null)
			{
				return DropImage(imageToLookFor, secondsToWait, searchRegion, offset, origin);
			}

			return false;
		}
コード例 #22
0
ファイル: AutomationRunner.cs プロジェクト: eriser/agg-sharp
		public bool DropByName(string widgetName, double secondsToWait = 0, SearchRegion searchRegion = null, Point2D offset = default(Point2D), ClickOrigin origin = ClickOrigin.Center)
		{
			SystemWindow containingWindow;
			GuiWidget widgetToClick = GetWidgetByName(widgetName, out containingWindow, secondsToWait, searchRegion);
			if (widgetToClick != null)
			{
				RectangleDouble childBounds = widgetToClick.TransformToParentSpace(containingWindow, widgetToClick.LocalBounds);

				if (origin == ClickOrigin.Center)
				{
					offset.x += (int)childBounds.Width / 2;
					offset.y += (int)childBounds.Height / 2;
				}

				Point2D screenPosition = SystemWindowToScreen(new Point2D(childBounds.Left + offset.x, childBounds.Bottom + offset.y), containingWindow);
				SetMouseCursorPosition(screenPosition.x, screenPosition.y);
				NativeMethods.mouse_event(NativeMethods.MOUSEEVENTF_LEFTUP, screenPosition.x, screenPosition.y, 0, 0);

				return true;
			}

			return false;
		}
コード例 #23
0
        public bool DragDropImage(ImageBuffer imageNeedleDrag, ImageBuffer imageNeedleDrop, double secondsToWait = 0, SearchRegion searchRegion = null, Point2D offsetDrag = default(Point2D), ClickOrigin originDrag = ClickOrigin.Center,
                                  Point2D offsetDrop = default(Point2D), ClickOrigin originDrop = ClickOrigin.Center)
        {
            if (searchRegion == null)
            {
                searchRegion = GetScreenRegion();
            }

            if (DragImage(imageNeedleDrag, secondsToWait, searchRegion, offsetDrag, originDrag))
            {
                return(DropImage(imageNeedleDrop, secondsToWait, searchRegion, offsetDrop, originDrop));
            }

            return(false);
        }
コード例 #24
0
ファイル: AutomationRunner.cs プロジェクト: eriser/agg-sharp
		public bool NameExists(string widgetName, SearchRegion searchRegion = null)
		{
			foreach (SystemWindow window in SystemWindow.OpenWindows)
			{
				List<GuiWidget> foundChildren = new List<GuiWidget>();
				window.FindNamedChildrenRecursive(widgetName, foundChildren);
				if (foundChildren.Count > 0)
				{
					foreach (GuiWidget foundChild in foundChildren)
					{
						if (foundChild.ActuallyVisibleOnScreen())
						{
							return true;
						}
					}
				}
			}

			return false;
		}
コード例 #25
0
		public List<GetResults> GetWidgetsByName(string widgetName, double secondsToWait = 0, SearchRegion searchRegion = null)
		{
			if (secondsToWait > 0)
			{
				bool foundWidget = WaitForName(widgetName, secondsToWait);
				if (!foundWidget)
				{
					return null;
				}
			}

			List<GetResults> namedWidgetsInRegion = new List<GetResults>();
			foreach (SystemWindow systemWindow in SystemWindow.OpenWindows)
			{
				if (searchRegion != null) // only add the widgets that are in the screen region
				{
					List<GuiWidget> namedWidgets = new List<GuiWidget>();
					systemWindow.FindNamedChildrenRecursive(widgetName, namedWidgets);
					foreach (GuiWidget namedWidget in namedWidgets)
					{
						if (namedWidget.ActuallyVisibleOnScreen())
						{
							RectangleDouble childBounds = namedWidget.TransformToParentSpace(systemWindow, namedWidget.LocalBounds);

							ScreenRectangle screenRect = SystemWindowToScreen(childBounds, systemWindow);
							ScreenRectangle result;
							if (ScreenRectangle.Intersection(searchRegion.ScreenRect, screenRect, out result))
							{
								namedWidgetsInRegion.Add(new GetResults()
								{
									widget = namedWidget,
									containingSystemWindow = systemWindow,
								});
							}
						}
					}
				}
				else // add every named widget found
				{
					List<GuiWidget> namedWidgets = new List<GuiWidget>();
					systemWindow.FindNamedChildrenRecursive(widgetName, namedWidgets);
					foreach (GuiWidget namedWidget in namedWidgets)
					{
						if (namedWidget.ActuallyVisibleOnScreen())
						{
							namedWidgetsInRegion.Add(new GetResults()
							{
								widget = namedWidget,
								containingSystemWindow = systemWindow,
							});
						}
					}
				}
			}

			return namedWidgetsInRegion;
		}
コード例 #26
0
		public SearchRegion GetRegionByName(string widgetName, double secondsToWait = 0, SearchRegion searchRegion = null)
		{
			SystemWindow containingWindow;
			GuiWidget namedWidget = GetWidgetByName(widgetName, out containingWindow, secondsToWait, searchRegion);

			if (namedWidget != null)
			{
				RectangleDouble childBounds = namedWidget.TransformToParentSpace(containingWindow, namedWidget.LocalBounds);

				ScreenRectangle screenPosition = SystemWindowToScreen(childBounds, containingWindow);

				return new SearchRegion()
				{
					ScreenRect = screenPosition,
				};
			}

			return null;
		}
コード例 #27
0
		public GuiWidget GetWidgetByName(string widgetName, out SystemWindow containingWindow, double secondsToWait = 0, SearchRegion searchRegion = null)
		{
			containingWindow = null;

			List<GetResults> getResults = GetWidgetsByName(widgetName, secondsToWait, searchRegion);
			if (getResults != null 
				&& getResults.Count > 0)
			{
				containingWindow = getResults[0].containingSystemWindow;
				return getResults[0].widget;
			}

			return null;
		}
コード例 #28
0
		public bool MoveToImage(string imageName, int xOffset = 0, int yOffset = 0, ClickOrigin origin = ClickOrigin.Center, SearchRegion searchRegion = null)
		{
			throw new NotImplementedException();
		}
コード例 #29
0
		public bool ImageExists(ImageBuffer imageNeedle, double secondsToWait = 0, SearchRegion searchRegion = null)
		{
			if (secondsToWait > 0)
			{
				bool foundImage = WaitForImage(imageNeedle, secondsToWait, searchRegion);
				if (!foundImage)
				{
					return false;
				}
			}

			if (searchRegion == null)
			{
				searchRegion = GetScreenRegion();
			}

			Vector2 matchPosition;
			double bestMatch;
			if (searchRegion.Image.FindLeastSquaresMatch(imageNeedle, out matchPosition, out bestMatch, MatchLimit))
			{
				return true;
			}

			return false;
		}
コード例 #30
0
		public bool DropImage(ImageBuffer imageNeedle, int xOffset = 0, int yOffset = 0, ClickOrigin origin = ClickOrigin.Center, SearchRegion searchRegion = null)
		{
			if (origin == ClickOrigin.Center)
			{
				xOffset += imageNeedle.Width / 2;
				yOffset += imageNeedle.Height / 2;
			}

			if (searchRegion == null)
			{
				searchRegion = GetScreenRegion();
			}

			Vector2 matchPosition;
			double bestMatch;
			if (searchRegion.Image.FindLeastSquaresMatch(imageNeedle, out matchPosition, out bestMatch, MatchLimit))
			{
				int screenHeight = NativeMethods.GetCurrentScreenHeight();
				int clickY = (int)(searchRegion.ScreenRect.Bottom + matchPosition.y + yOffset);
				int clickYOnScreen = screenHeight - clickY; // invert to put it on the screen

				Point2D screenPosition = new Point2D((int)matchPosition.x + xOffset, clickYOnScreen);
				SetMouseCursorPosition(screenPosition.x, screenPosition.y);
				NativeMethods.mouse_event(NativeMethods.MOUSEEVENTF_LEFTUP, screenPosition.x, screenPosition.y, 0, 0);

				return true;
			}

			return false;
		}
コード例 #31
0
ファイル: AutomationRunner.cs プロジェクト: eriser/agg-sharp
		public bool DragDropImage(string imageNameDrag, string imageNameDrop, double secondsToWait = 0, SearchRegion searchRegion = null, Point2D offsetDrag = default(Point2D), ClickOrigin originDrag = ClickOrigin.Center,
			Point2D offsetDrop = default(Point2D), ClickOrigin originDrop = ClickOrigin.Center)
		{
			ImageBuffer imageNeedleDrag = LoadImageFromSourcFolder(imageNameDrag);
			if (imageNeedleDrag != null)
			{
				ImageBuffer imageNeedleDrop = LoadImageFromSourcFolder(imageNameDrop);
				if (imageNeedleDrop != null)
				{
					return DragDropImage(imageNeedleDrag, imageNeedleDrop, secondsToWait, searchRegion, offsetDrag, originDrag, offsetDrop, originDrop);
				}
			}

			return false;
		}
コード例 #32
0
		public bool DragDropByName(string widgetNameDrag, string widgetNameDrop, int xOffsetDrag = 0, int yOffsetDrag = 0, ClickOrigin originDrag = ClickOrigin.Center,
			int xOffsetDrop = 0, int yOffsetDrop = 0, ClickOrigin originDrop = ClickOrigin.Center, double secondsToWait = 0, SearchRegion searchRegion = null)
		{
			if (DragByName(widgetNameDrag, xOffsetDrag, yOffsetDrag, originDrag, secondsToWait, searchRegion))
			{
				return DropByName(widgetNameDrop, xOffsetDrop, yOffsetDrop, originDrop, secondsToWait, searchRegion);
			}

			return false;
		}
コード例 #33
0
 public bool DoubleClickByName(string widgetName, double secondsToWait = 0, SearchRegion searchRegion = null, Point2D offset = default(Point2D), ClickOrigin origin = ClickOrigin.Center)
 {
     throw new NotImplementedException();
 }
コード例 #34
0
		public bool DoubleClickByName(string widgetName, int xOffset = 0, int yOffset = 0, ClickOrigin origin = ClickOrigin.Center, SearchRegion searchRegion = null)
		{
			throw new NotImplementedException();
		}
コード例 #35
0
		public bool DropImage(string imageName, int xOffset = 0, int yOffset = 0, ClickOrigin origin = ClickOrigin.Center, SearchRegion searchRegion = null)
		{
			ImageBuffer imageToLookFor = LoadImageFromSourcFolder(imageName);
			if (imageToLookFor != null)
			{
				return DropImage(imageToLookFor, xOffset, yOffset, origin, searchRegion);
			}

			return false;
		}
コード例 #36
0
		public bool DragDropImage(ImageBuffer imageNeedleDrag, ImageBuffer imageNeedleDrop, int xOffsetDrag = 0, int yOffsetDrag = 0, ClickOrigin originDrag = ClickOrigin.Center,
			int xOffsetDrop = 0, int yOffsetDrop = 0, ClickOrigin originDrop = ClickOrigin.Center,
			SearchRegion searchRegion = null)
		{
			if (searchRegion == null)
			{
				searchRegion = GetScreenRegion();
			}

			if (DragImage(imageNeedleDrag, xOffsetDrag, yOffsetDrag, originDrag, searchRegion))
			{
				return DropImage(imageNeedleDrop, xOffsetDrop, yOffsetDrop, originDrop, searchRegion);
			}

			return false;
		}
コード例 #37
0
 public void DoubleClickByName(string widgetName, SearchRegion searchRegion = null, Point2D offset = default(Point2D), ClickOrigin origin = ClickOrigin.Center)
 {
     this.ClickByName(widgetName, searchRegion, offset, origin, isDoubleClick: true);
 }
コード例 #38
0
		public bool NameExists(string widgetName, SearchRegion searchRegion = null)
		{
			foreach (SystemWindow window in SystemWindow.OpenWindows)
			{
				GuiWidget widgetToClick = window.FindNamedChildRecursive(widgetName);
				if (widgetToClick != null)
				{
					if (widgetToClick.ActuallyVisibleOnScreen())
					{
						return true;
					}
				}
			}

			return false;
		}
コード例 #39
0
ファイル: AutomationRunner.cs プロジェクト: eriser/agg-sharp
		public bool DoubleClickByName(string widgetName, double secondsToWait = 0, SearchRegion searchRegion = null, Point2D offset = default(Point2D), ClickOrigin origin = ClickOrigin.Center)
		{
			throw new NotImplementedException();
		}
コード例 #40
0
		public bool WaitForImage(string imageName, double secondsToWait, SearchRegion searchRegion = null)
		{
			ImageBuffer imageToLookFor = LoadImageFromSourcFolder(imageName);
			if (imageToLookFor != null)
			{
				return WaitForImage(imageToLookFor, secondsToWait, searchRegion);
			}

			return false;
		}
コード例 #41
0
        public bool DragDropImage(string imageNameDrag, string imageNameDrop, double secondsToWait = 0, SearchRegion searchRegion = null, Point2D offsetDrag = default(Point2D), ClickOrigin originDrag = ClickOrigin.Center,
                                  Point2D offsetDrop = default(Point2D), ClickOrigin originDrop = ClickOrigin.Center)
        {
            ImageBuffer imageNeedleDrag = LoadImageFromSourceFolder(imageNameDrag);

            if (imageNeedleDrag != null)
            {
                ImageBuffer imageNeedleDrop = LoadImageFromSourceFolder(imageNameDrop);
                if (imageNeedleDrop != null)
                {
                    return(DragDropImage(imageNeedleDrag, imageNeedleDrop, secondsToWait, searchRegion, offsetDrag, originDrag, offsetDrop, originDrop));
                }
            }

            return(false);
        }
コード例 #42
0
		public bool WaitForImage(ImageBuffer imageNeedle, double secondsToWait, SearchRegion searchRegion = null)
		{
			Stopwatch timeWaited = Stopwatch.StartNew();
			while (!ImageExists(imageNeedle)
				&& timeWaited.Elapsed.TotalSeconds < secondsToWait)
			{
				Wait(.05);
			}

			if (timeWaited.Elapsed.TotalSeconds > secondsToWait)
			{
				return false;
			}

			return true;
		}
コード例 #43
0
ファイル: AutomationRunner.cs プロジェクト: eriser/agg-sharp
		public bool DragDropByName(string widgetNameDrag, string widgetNameDrop, double secondsToWait = 0, SearchRegion searchRegion = null, Point2D offsetDrag = default(Point2D), ClickOrigin originDrag = ClickOrigin.Center, Point2D offsetDrop = default(Point2D), ClickOrigin originDrop = ClickOrigin.Center)
		{
			if (DragByName(widgetNameDrag, secondsToWait, searchRegion, offsetDrag, originDrag))
			{
				return DropByName(widgetNameDrop, secondsToWait, searchRegion, offsetDrop, originDrop);
			}

			return false;
		}
コード例 #44
0
		public bool ClickImage(ImageBuffer imageNeedle, int xOffset = 0, int yOffset = 0, ClickOrigin origin = ClickOrigin.Center, SearchRegion searchRegion = null, MouseButtons mouseButtons = MouseButtons.Left)
		{
			if (origin == ClickOrigin.Center)
			{
				xOffset += imageNeedle.Width / 2;
				yOffset += imageNeedle.Height / 2;
			}

			if (searchRegion == null)
			{
				searchRegion = GetScreenRegion();
			}

			Vector2 matchPosition;
			double bestMatch;
			if (searchRegion.Image.FindLeastSquaresMatch(imageNeedle, out matchPosition, out bestMatch, MatchLimit))
			{
				int screenHeight = NativeMethods.GetCurrentScreenHeight();
				int clickY = (int)(searchRegion.ScreenRect.Bottom + matchPosition.y + yOffset);
				int clickYOnScreen = screenHeight - clickY; // invert to put it on the screen

				Point2D screenPosition = new Point2D((int)matchPosition.x + xOffset, clickYOnScreen);
				SetMouseCursorPosition(screenPosition.x, screenPosition.y);
				switch (mouseButtons)
				{
					case MouseButtons.None:
						break;

					case MouseButtons.Left:
						NativeMethods.mouse_event(NativeMethods.MOUSEEVENTF_LEFTDOWN, screenPosition.x, screenPosition.y, 0, 0);
						Wait(upDelaySeconds);
						NativeMethods.mouse_event(NativeMethods.MOUSEEVENTF_LEFTUP, screenPosition.x, screenPosition.y, 0, 0);
						break;

					case MouseButtons.Right:
						NativeMethods.mouse_event(NativeMethods.MOUSEEVENTF_RIGHTDOWN, screenPosition.x, screenPosition.y, 0, 0);
						Wait(upDelaySeconds);
						NativeMethods.mouse_event(NativeMethods.MOUSEEVENTF_RIGHTUP, screenPosition.x, screenPosition.y, 0, 0);
						break;

					case MouseButtons.Middle:
						NativeMethods.mouse_event(NativeMethods.MOUSEEVENTF_MIDDLEDOWN, screenPosition.x, screenPosition.y, 0, 0);
						Wait(upDelaySeconds);
						NativeMethods.mouse_event(NativeMethods.MOUSEEVENTF_MIDDLEUP, screenPosition.x, screenPosition.y, 0, 0);
						break;

					default:
						break;
				}

				return true;
			}

			return false;
		}
コード例 #45
0
        public SearchRegion GetRegionByName(string widgetName, double secondsToWait = 0, SearchRegion searchRegion = null)
        {
            SystemWindow containingWindow;
            GuiWidget    namedWidget = GetWidgetByName(widgetName, out containingWindow, secondsToWait, searchRegion);

            if (namedWidget != null)
            {
                RectangleDouble childBounds = namedWidget.TransformToParentSpace(containingWindow, namedWidget.LocalBounds);

                ScreenRectangle screenPosition = SystemWindowToScreen(childBounds, containingWindow);

                return(new SearchRegion(this)
                {
                    ScreenRect = screenPosition,
                });
            }

            return(null);
        }
コード例 #46
0
		public bool ClickImage(string imageName, int xOffset = 0, int yOffset = 0, ClickOrigin origin = ClickOrigin.Center, SearchRegion searchRegion = null, MouseButtons mouseButtons = MouseButtons.Left)
		{
			ImageBuffer imageToLookFor = LoadImageFromSourcFolder(imageName);
			if (imageToLookFor != null)
			{
				return ClickImage(imageToLookFor, xOffset, yOffset, origin, searchRegion, mouseButtons);
			}

			return false;
		}
コード例 #47
0
        public List <GetResults> GetWidgetsByName(string widgetName, double secondsToWait = 0, SearchRegion searchRegion = null)
        {
            if (secondsToWait > 0)
            {
                bool foundWidget = WaitForName(widgetName, secondsToWait);
                if (!foundWidget)
                {
                    return(null);
                }
            }

            List <GetResults> namedWidgetsInRegion = new List <GetResults>();

            for (int i = SystemWindow.AllOpenSystemWindows.Count - 1; i >= 0; i--)
            {
                SystemWindow systemWindow = SystemWindow.AllOpenSystemWindows[i];
                if (searchRegion != null)                 // only add the widgets that are in the screen region
                {
                    List <GuiWidget> namedWidgets = new List <GuiWidget>();
                    systemWindow.FindNamedChildrenRecursive(widgetName, namedWidgets);
                    foreach (GuiWidget namedWidget in namedWidgets)
                    {
                        if (namedWidget.ActuallyVisibleOnScreen())
                        {
                            RectangleDouble childBounds = namedWidget.TransformToParentSpace(systemWindow, namedWidget.LocalBounds);

                            ScreenRectangle screenRect = SystemWindowToScreen(childBounds, systemWindow);
                            ScreenRectangle result;
                            if (ScreenRectangle.Intersection(searchRegion.ScreenRect, screenRect, out result))
                            {
                                namedWidgetsInRegion.Add(new GetResults()
                                {
                                    widget = namedWidget,
                                    containingSystemWindow = systemWindow,
                                });
                            }
                        }
                    }
                }
                else                 // add every named widget found
                {
                    List <GuiWidget> namedWidgets = new List <GuiWidget>();
                    systemWindow.FindNamedChildrenRecursive(widgetName, namedWidgets);
                    foreach (GuiWidget namedWidget in namedWidgets)
                    {
                        if (namedWidget.ActuallyVisibleOnScreen())
                        {
                            namedWidgetsInRegion.Add(new GetResults()
                            {
                                widget = namedWidget,
                                containingSystemWindow = systemWindow,
                            });
                        }
                    }
                }
            }

            return(namedWidgetsInRegion);
        }
コード例 #48
0
 public object GetObjectByName(string widgetName, out SystemWindow containingWindow, double secondsToWait = 0, SearchRegion searchRegion = null)
 {
     return(GetObjectByName(widgetName, out containingWindow, out _, secondsToWait, searchRegion));
 }
コード例 #49
0
        public bool DragDropByName(string widgetNameDrag, string widgetNameDrop, double secondsToWait = 0, SearchRegion searchRegion = null, Point2D offsetDrag = default(Point2D), ClickOrigin originDrag = ClickOrigin.Center, Point2D offsetDrop = default(Point2D), ClickOrigin originDrop = ClickOrigin.Center)
        {
            if (DragByName(widgetNameDrag, secondsToWait, searchRegion, offsetDrag, originDrag))
            {
                return(DropByName(widgetNameDrop, secondsToWait, searchRegion, offsetDrop, originDrop));
            }

            return(false);
        }
コード例 #50
0
        public object GetObjectByName(string widgetName, out SystemWindow containingWindow, out Point2D offsetHint, double secondsToWait = 0, SearchRegion searchRegion = null, bool onlyVisible = true)
        {
            containingWindow = null;
            offsetHint       = Point2D.Zero;

            List <GetByNameResults> getResults = GetWidgetsByName(widgetName, secondsToWait, searchRegion, onlyVisible);

            if (getResults != null &&
                getResults.Count > 0)
            {
                containingWindow = getResults[0].ContainingSystemWindow;
                offsetHint       = getResults[0].OffsetHint;
                getResults[0].Widget.DebugShowBounds = true;
                UiThread.RunOnIdle(() => getResults[0].Widget.DebugShowBounds = false, 1);

                return(getResults[0].NamedObject);
            }

            return(null);
        }
コード例 #51
0
ファイル: AutomationRunner.cs プロジェクト: eriser/agg-sharp
		public bool DragDropImage(ImageBuffer imageNeedleDrag, ImageBuffer imageNeedleDrop, double secondsToWait = 0, SearchRegion searchRegion = null, Point2D offsetDrag = default(Point2D), ClickOrigin originDrag = ClickOrigin.Center,
			Point2D offsetDrop = default(Point2D), ClickOrigin originDrop = ClickOrigin.Center)
		{
			if (searchRegion == null)
			{
				searchRegion = GetScreenRegion();
			}

			if (DragImage(imageNeedleDrag, secondsToWait, searchRegion, offsetDrag, originDrag))
			{
				return DropImage(imageNeedleDrop, secondsToWait, searchRegion, offsetDrop, originDrop);
			}

			return false;
		}
コード例 #52
0
        public List <GetByNameResults> GetWidgetsByName(string widgetName, double secondsToWait = 0, SearchRegion searchRegion = null, bool onlyVisible = true)
        {
            if (secondsToWait > 0)
            {
                bool foundWidget = WaitForName(widgetName, secondsToWait, onlyVisible);
                if (!foundWidget)
                {
                    return(null);
                }
            }

            List <GetByNameResults> namedWidgetsInRegion = new List <GetByNameResults>();

            foreach (var systemWindow in SystemWindow.AllOpenSystemWindows.Reverse())
            {
                if (searchRegion != null)                 // only add the widgets that are in the screen region
                {
                    List <GuiWidget.WidgetAndPosition> namedWidgets = new List <GuiWidget.WidgetAndPosition>();
                    systemWindow.FindNamedChildrenRecursive(widgetName, namedWidgets);
                    foreach (GuiWidget.WidgetAndPosition widgetAndPosition in namedWidgets)
                    {
                        if (!onlyVisible ||
                            widgetAndPosition.widget.ActuallyVisibleOnScreen())
                        {
                            RectangleDouble childBounds = widgetAndPosition.widget.TransformToParentSpace(systemWindow, widgetAndPosition.widget.LocalBounds);

                            ScreenRectangle screenRect = SystemWindowToScreen(childBounds, systemWindow);
                            ScreenRectangle result;
                            if (ScreenRectangle.Intersection(searchRegion.ScreenRect, screenRect, out result))
                            {
                                namedWidgetsInRegion.Add(new GetByNameResults(widgetAndPosition.widget, widgetAndPosition.position, systemWindow, widgetAndPosition.NamedObject));
                            }
                        }
                    }
                }
                else                 // add every named widget found
                {
                    List <GuiWidget.WidgetAndPosition> namedWidgets = new List <GuiWidget.WidgetAndPosition>();
                    systemWindow.FindNamedChildrenRecursive(widgetName, namedWidgets);
                    foreach (GuiWidget.WidgetAndPosition namedWidget in namedWidgets)
                    {
                        if (!onlyVisible ||
                            namedWidget.widget.ActuallyVisibleOnScreen())
                        {
                            namedWidgetsInRegion.Add(new GetByNameResults(namedWidget.widget, namedWidget.position, systemWindow, namedWidget.NamedObject));
                        }
                    }
                }
            }

            return(namedWidgetsInRegion);
        }
コード例 #53
0
		public bool MoveToByName(string widgetName, int xOffset = 0, int yOffset = 0, ClickOrigin origin = ClickOrigin.Center, double secondsToWait = 0, SearchRegion searchRegion = null)
		{
			SystemWindow containingWindow;
			GuiWidget widgetToClick = GetWidgetByName(widgetName, out containingWindow, secondsToWait, searchRegion);
			if (widgetToClick != null)
			{
				RectangleDouble childBounds = widgetToClick.TransformToParentSpace(containingWindow, widgetToClick.LocalBounds);

				if (origin == ClickOrigin.Center)
				{
					xOffset += (int)childBounds.Width / 2;
					yOffset += (int)childBounds.Height / 2;
				}

				Point2D screenPosition = SystemWindowToScreen(new Point2D(childBounds.Left + xOffset, childBounds.Bottom + yOffset), containingWindow);
				SetMouseCursorPosition(screenPosition.x, screenPosition.y);

				return true;
			}

			return false;
		}
コード例 #54
0
		public bool DragDropImage(string imageNameDrag, string imageNameDrop, int xOffsetDrag = 0, int yOffsetDrag = 0, ClickOrigin originDrag = ClickOrigin.Center,
			int xOffsetDrop = 0, int yOffsetDrop = 0, ClickOrigin originDrop = ClickOrigin.Center,
			SearchRegion searchRegion = null)
		{
			ImageBuffer imageNeedleDrag = LoadImageFromSourcFolder(imageNameDrag);
			if (imageNeedleDrag != null)
			{
				ImageBuffer imageNeedleDrop = LoadImageFromSourcFolder(imageNameDrop);
				if (imageNeedleDrop != null)
				{
					return DragDropImage(imageNeedleDrag, imageNeedleDrop, xOffsetDrag, yOffsetDrag, originDrag, xOffsetDrop, yOffsetDrop, originDrop, searchRegion);
				}
			}

			return false;
		}