public void Execute(Arguments arguments) { if (arguments.Threshold.Value < 0 || arguments.Threshold.Value > 1) { throw new ArgumentOutOfRangeException("Threshold must be a value from 0 to 1."); } using (Bitmap bitmap1 = Imaging.OpenImageFile(arguments.Image1.Value, nameof(arguments.Image1))) using (Bitmap bitmap2 = (string.IsNullOrEmpty(arguments.Image2?.Value)) ? RobotWin32.GetPartOfScreen( Imaging.ParseRectanglePositionFromArguments(arguments.ScreenSearchArea.Value, arguments.Relative.Value), bitmap1.PixelFormat) : Imaging.OpenImageFile(arguments.Image2.Value, nameof(arguments.Image2))) { Rectangle foundRectangle = Imaging.IsImageInImage(bitmap1, bitmap2, (double)arguments.Threshold.Value); if (foundRectangle == Rectangle.Empty) { throw new ArgumentException("Image was not found in specified search area."); } else { Point foundPoint = (!arguments.CenterResult.Value) ? new Point(foundRectangle.X, foundRectangle.Y) : new Point(foundRectangle.X + foundRectangle.Width / 2, foundRectangle.Y + foundRectangle.Height / 2); foundPoint = new Point(foundPoint.X + arguments.OffsetX.Value, foundPoint.Y + arguments.OffsetY.Value); Scripter.Variables.SetVariableValue(arguments.Result.Value, new PointStructure(foundPoint)); } } }
private void highlightToolStripMenuItem_Click(object sender, EventArgs e) { try { if (controlsTree.SelectedNode != null) { if (controlsTree.SelectedNode.Tag is UIElement uiElement) { var element = UIElement.FromWPath(uiElement.ToWPath()); if (element != null) { var window = GetTopLevelWindow(uiElement.AutomationElement); if (window != null) { var iHandle = window.FrameworkAutomationElement.NativeWindowHandle; if (iHandle != IntPtr.Zero) { RobotWin32.BringWindowToFront(iHandle); var rect = element.GetRectangle(); if (rect != null) { InitializeRectangleForm(rect); } } } } } } } catch (Exception ex) { RobotMessageBox.Show(ex.Message, "Error"); } }
public void Execute(Arguments arguments) { var wrapper = MsCrmManager.CurrentCRM; if (wrapper == null) { throw new ApplicationException("Could not activate Dynamics CRM instance. It has to be attached first."); } IntPtr iHandle = wrapper.Ie.NativeBrowser.hWnd; Scripter.Log.Log(AbstractLogger.Level.Info, "Window '" + wrapper.Title + "' has been found"); Scripter.LastWindow = (iHandle); RobotWin32.BringWindowToFront(iHandle); if (arguments.Style.Value.ToLower() == "maximize") { RobotWin32.ShowWindow(iHandle, RobotWin32.ShowWindowEnum.Maximize); } else if (arguments.Style.Value.ToLower() == "minimize") { RobotWin32.ShowWindow(iHandle, RobotWin32.ShowWindowEnum.Minimize); } else if (arguments.Style.Value.ToLower() == "normal") { RobotWin32.ShowWindow(iHandle, RobotWin32.ShowWindowEnum.Restore); } }
public void Execute(Arguments arguments) { manager = AbbyyManager.Instance; System.Drawing.Rectangle rectangle = !arguments.Relative.Value ? arguments.Area.Value : arguments.Area.Value.ToAbsoluteCoordinates(); System.Drawing.Bitmap partOfScreen = RobotWin32.GetPartOfScreen(rectangle); IEngine engine = manager.Engine; DocumentProcessingParams processingParams = engine.CreateDocumentProcessingParams(); RecognizerParams recognizingParams = processingParams.PageProcessingParams.RecognizerParams; recognizingParams.SetPredefinedTextLanguage(arguments.Language.Value); engine.LoadPredefinedProfile(AbbyyManager.TextAccuracyProfile); FRDocument imageDocument = engine.CreateFRDocument(); using (System.IO.MemoryStream stream = new System.IO.MemoryStream()) { partOfScreen.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp); stream.Position = 0; IReadStream imageStream = new StreamNet2AbbyyAdapter(stream); imageDocument.AddImageFileFromStream(imageStream); } imageDocument.Process(processingParams); Scripter.Variables.SetVariableValue(arguments.Result.Value, new TextStructure(imageDocument.PlainText.Text)); }
public void BringWindowToForeground() { if (MainWindowHandle != IntPtr.Zero) { RobotWin32.SetForegroundWindow(MainWindowHandle); } }
public void WaitForExistingImageTest() { testerApp = SDK.Tester.RunFormTester("Title TestApp"); Color color = Color.Gainsboro; string colorCode = "FFDCDCDC"; RobotWin32.ShowWindow(testerApp.MainWindowHandle, RobotWin32.ShowWindowEnum.ShowNormal); Scripter scripter = new Scripter(); scripter.InitVariables.Clear(); scripter.RunLine("window TestApp"); scripter.InitVariables.Add(nameof(colorCode), new TextStructure(colorCode)); scripter.Text = $@"keyboard {TextChar}FocusOnControl tbColorRGB{TextChar} keyboard {SpecialChars.KeyBegin}enter{SpecialChars.KeyEnd} keyboard {TextChar}{SpecialChars.Variable}{nameof(colorCode)}{TextChar} keyboard {SpecialChars.KeyBegin}enter{SpecialChars.KeyEnd}"; scripter.Run(); string path1 = Assembly.GetExecutingAssembly().UnpackResourceToFile("Resources." + nameof(Resources.littleGrayRectangle), "bmp"); scripter.RunLine($"waitfor.image image {SpecialChars.Text}{path1}{SpecialChars.Text}"); }
public static Rectangle ParseRectanglePositionFromArguments(Rectangle screenSearchArea, bool relative) { Rectangle result = screenSearchArea; if (result.X < 0 || result.Y < 0 || result.Width < 1 || result.Height < 1) { throw new ArgumentException("ScreenSearchArea argument's parts can't be negative. Both width and height must be bigger than zero."); } if (relative) { IntPtr handle = RobotWin32.GetForegroundWindow(); if (handle.ToInt32() == 0) { throw new ApplicationException("Cannot find foreground window."); } RobotWin32.Rect foregroundWindowRect = new RobotWin32.Rect(); if (RobotWin32.GetWindowRectangle(handle, ref foregroundWindowRect) == false) { throw new ApplicationException("Cannot get foreground window rect."); } result = new Rectangle(result.X + foregroundWindowRect.Left, result.Y + foregroundWindowRect.Top, result.Width, result.Height); } return(result); }
public void Execute(Arguments arguments) { var control = AccessManager.CurrentAccess.GetControlByPath(arguments.Path.Value); var handle = (IntPtr)control.GetFormHwnd(); RobotWin32.BringWindowToFront(handle); RobotWin32.ShowWindow(handle, RobotWin32.ShowWindowEnum.Maximize); control.SetFocus(); }
private void ActivateBrowserWindow(MsCrmWrapper wrapper) { if (wrapper == null) { throw new ApplicationException("Could not activate Dynamics CRM instance. It has to be attached first."); } IntPtr iHandle = wrapper.Ie.NativeBrowser.hWnd; Scripter.Log.Log(AbstractLogger.Level.Info, "Window '" + wrapper.Title + "' has been found"); Scripter.LastWindow = (iHandle); RobotWin32.BringWindowToFront(iHandle); }
internal void OpenAccessObject(AccessObjectModel report) { try { var app = GetCurrentApplication(); var name = report.FullName ?? report.Name; switch (report.Type) { case MSAccess.AcObjectType.acReport: app.DoCmd.OpenReport(name); break; case MSAccess.AcObjectType.acTable: app.DoCmd.OpenTable(name, MSAccess.AcView.acViewNormal, MSAccess.AcOpenDataMode.acReadOnly); break; case MSAccess.AcObjectType.acServerView: app.DoCmd.OpenView(name, MSAccess.AcView.acViewNormal, MSAccess.AcOpenDataMode.acReadOnly); break; case MSAccess.AcObjectType.acStoredProcedure: app.DoCmd.OpenStoredProcedure(name, MSAccess.AcView.acViewNormal, MSAccess.AcOpenDataMode.acReadOnly); break; case MSAccess.AcObjectType.acQuery: app.DoCmd.OpenQuery(name, MSAccess.AcView.acViewNormal, MSAccess.AcOpenDataMode.acReadOnly); break; case MSAccess.AcObjectType.acFunction: app.DoCmd.OpenFunction(name, MSAccess.AcView.acViewNormal, MSAccess.AcOpenDataMode.acReadOnly); break; case MSAccess.AcObjectType.acDiagram: app.DoCmd.OpenDiagram(name); break; case MSAccess.AcObjectType.acMacro: app.DoCmd.RunMacro(name, 1, true); break; default: throw new NotImplementedException($"Opener for {report.TypeName} not implemented."); } RobotWin32.BringWindowToFront((IntPtr)app.hWndAccessApp()); } catch (Exception ex) { RobotMessageBox.Show(ex.Message); } }
public void WaitForImageTest() { Color color = Color.Pink; string colorCode = "FFFFC0CB"; string path = Assembly.GetExecutingAssembly().UnpackResourceToFile("Resources." + nameof(Resources.smallPink), "bmp"); Scripter scripter = new Scripter(); testerApp = SDK.Tester.RunFormTester($"CenterOfScreen FocusOnControl tbColorRGB ChangeColor {colorCode} "); RobotWin32.ShowWindow(testerApp.MainWindowHandle, RobotWin32.ShowWindowEnum.ShowNormal); scripter.Text = $"waitfor.image image {SpecialChars.Text}{path}{SpecialChars.Text} timeout 8000"; scripter.Run(); }
public void Close() { try { int hWnd = application.Application.Hwnd; uint processId; RobotWin32.GetWindowThreadProcessId((IntPtr)hWnd, out processId); Process proc = Process.GetProcessById((int)processId); proc.Kill(); } catch (Exception ex) { throw new ApplicationException($"Error occurred while closing current Excel Instance. Message: {ex.Message}"); } }
public void Execute(Arguments arguments) { string errorJump = arguments.ErrorJump != null && arguments.ErrorJump != null?arguments.ErrorJump.ToString() : string.Empty; string host = arguments.Host.Value; //telnet = System.Diagnostics.Process.Start(pathToTelnet, host); putty = System.Diagnostics.Process.Start(pathToPutty, "-load AS400"); System.Threading.Thread.Sleep(2000); //RobotWin32.ShowWindow(telnet.MainWindowHandle, RobotWin32.ShowWindowEnum.ShowNormal); //IntPtr iHandle = RobotWin32.FindWindow(null, telnet.MainWindowTitle); RobotWin32.ShowWindow(putty.MainWindowHandle, RobotWin32.ShowWindowEnum.ShowNormal); IntPtr iHandle = RobotWin32.FindWindow(null, putty.MainWindowTitle); RobotWin32.SetForegroundWindow(iHandle); }
public void Execute(Arguments arguments) { Rectangle rectangle = !arguments.Relative.Value ? arguments.Area.Value : arguments.Area.Value.ToAbsoluteCoordinates(); Bitmap partOfScreen = RobotWin32.GetPartOfScreen(rectangle); int timeout = (int)arguments.Timeout.Value.TotalMilliseconds; List <string> languages = arguments.Languages.Value.Split(',').ToList(); string search = arguments.Search.Value; GoogleCloudApi googleApi = new GoogleCloudApi(); Rectangle output = googleApi.RecognizeText(partOfScreen, search, languages, timeout); if (Equals(output, new Rectangle(-1, -1, -1, -1))) { throw new NullReferenceException("Ocr was unable to find text"); } Scripter.Variables.SetVariableValue(arguments.Result.Value, new RectangleStructure(output)); }
public void Execute(Arguments arguments) { string host = arguments.Host.Value; string port = arguments.Port.Value; string pass = arguments.Password.Value; if (host == string.Empty || port == string.Empty || pass == string.Empty) { throw new ApplicationException("Host or port or pass is empty"); } testerApp = System.Diagnostics.Process.Start(pathToVNC, "-Scaling Fit -Encryption Server " + host + " " + port + " " + pass); bool result = RobotWin32.ShowWindow(testerApp.MainWindowHandle, RobotWin32.ShowWindowEnum.ShowNormal); Scripter.Variables.SetVariableValue(arguments.Result.Value, new BooleanStructure(result)); }
public void Execute(Arguments arguments) { var screenArea = !arguments.Relative.Value ? arguments.Area.Value : arguments.Area.Value.ToAbsoluteCoordinates(); var screenImage = RobotWin32.GetPartOfScreen(screenArea); var timeout = (int)arguments.Timeout.Value.TotalMilliseconds; var languages = arguments.Languages.Value.Split(',').ToList(); var googleApi = new GoogleCloudApi(); var text = googleApi.RecognizeText(screenImage, languages, timeout); if (string.IsNullOrEmpty(text)) { throw new NullReferenceException("Ocr was unable to find text"); } Scripter.Variables.SetVariableValue(arguments.Result.Value, new TextStructure(text)); }
public void Execute(Arguments arguments) { var screenArea = !arguments.Relative.Value ? arguments.Area.Value : arguments.Area.Value.ToAbsoluteCoordinates(); var screenImage = RobotWin32.GetPartOfScreen(screenArea); var timeout = (int)arguments.Timeout.Value.TotalMilliseconds; var languages = arguments.Languages.Value.Split(',').ToList(); var search = arguments.Search.Value; var googleApi = new GoogleCloudApi(); var rectangle = googleApi.FindTextPosition(screenImage, search, languages, timeout); if (rectangle == null) { throw new NullReferenceException("Ocr was unable to find text position"); } Scripter.Variables.SetVariableValue(arguments.Result.Value, new RectangleStructure(rectangle.Value)); }
public void Execute(Arguments arguments) { var pathToVNC = Path.Combine(AbstractSettingsContainer.Instance.UserDocsAddonFolder.FullName, @"VNC.exe"); var host = arguments.Host.Value; var port = arguments.Port.Value; var pass = arguments.Password.Value; if (host == string.Empty || port == string.Empty || pass == string.Empty) { throw new ApplicationException("Host or port or pass is empty"); } var testerApp = Process.Start(pathToVNC, "-Scaling Fit -Encryption Server " + host + " " + port + " " + pass); var result = RobotWin32.ShowWindow(testerApp.MainWindowHandle, RobotWin32.ShowWindowEnum.ShowNormal); Scripter.Variables.SetVariableValue(arguments.Result.Value, new BooleanStructure(result)); }
public void Execute(Arguments arguments) { var rectangle = arguments.Area.Value; if (!rectangle.IsValidRectangle()) { throw new ArgumentException("Argument Area is not a valid rectangle"); } if (arguments.Relative.Value) { var foregroundWindowRect = new RobotWin32.Rect(); RobotWin32.GetWindowRectangle(RobotWin32.GetForegroundWindow(), ref foregroundWindowRect); rectangle = new Rectangle(rectangle.X + foregroundWindowRect.Left, rectangle.Y + foregroundWindowRect.Top, Math.Min(rectangle.Width, foregroundWindowRect.Right - foregroundWindowRect.Left) - rectangle.X, Math.Min(rectangle.Height, foregroundWindowRect.Bottom - foregroundWindowRect.Top) - rectangle.Y); } var partOfScreen = RobotWin32.GetPartOfScreen(rectangle); var imgToParse = OcrOfflineHelper.RescaleImage(partOfScreen, arguments.Sensitivity.Value); var language = arguments.Language.Value; var dataPath = OcrOfflineHelper.GetResourcesFolder(language); try { using (var tEngine = new TesseractEngine(dataPath, language, EngineMode.TesseractAndCube)) using (var img = PixConverter.ToPix(imgToParse)) using (var page = tEngine.Process(img)) { var text = page.GetText(); if (string.IsNullOrEmpty(text)) { throw new NullReferenceException("Ocr was unable to find any text"); } Scripter.Variables.SetVariableValue(arguments.Result.Value, new Language.TextStructure(text)); } } catch (TesseractException) { throw new ApplicationException("Ocr engine exception, possibly missing language data in folder: " + dataPath); } catch (Exception e) { throw e; } }
public void Execute(Arguments arguments) { if (arguments.Threshold.Value < 0 || arguments.Threshold.Value > 1) { throw new ArgumentOutOfRangeException("Threshold must be a value from 0 to 1."); } using (Bitmap bitmap1 = Imaging.OpenImageFile(arguments.Image1.Value, nameof(arguments.Image1))) using (Bitmap bitmap2 = (string.IsNullOrEmpty(arguments.Image2?.Value)) ? RobotWin32.GetPartOfScreen( Imaging.ParseRectanglePositionFromArguments(arguments.ScreenSearchArea.Value, arguments.Relative.Value), bitmap1.PixelFormat) : Imaging.OpenImageFile(arguments.Image2.Value, nameof(arguments.Image2))) { bool found = Rectangle.Empty != Imaging.IsImageInImage(bitmap1, bitmap2, (double)arguments.Threshold.Value); Scripter.Variables.SetVariableValue(arguments.Result.Value, new BooleanStructure(found)); } }
public Rectangle GetRectangle() { if (AutomationElement.Properties.BoundingRectangle.TryGetValue(out var boundingRectNoDefault)) { return(boundingRectNoDefault); } if (AutomationElement.FrameworkAutomationElement.NativeWindowHandle != IntPtr.Zero) { var rect = new RobotWin32.Rect(); IntPtr wndHandle = AutomationElement.FrameworkAutomationElement.NativeWindowHandle; if (RobotWin32.GetWindowRectangle(wndHandle, ref rect)) { return(new Rectangle(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top)); } } throw new NotSupportedException("Cannot get rectangle for that kind of UI element."); }
public void Execute(Arguments arguments) { var pathToTelnet = Path.Combine(AbstractSettingsContainer.Instance.UserDocsAddonFolder.FullName, @"telnet.exe"); var pathToPutty = Path.Combine(AbstractSettingsContainer.Instance.UserDocsAddonFolder.FullName, @"putty.exe"); var errorJump = arguments.ErrorJump != null && arguments.ErrorJump != null?arguments.ErrorJump.ToString() : string.Empty; var host = arguments.Host.Value; //telnet = System.Diagnostics.Process.Start(pathToTelnet, host); var putty = Process.Start(pathToPutty, "-load AS400"); Thread.Sleep(2000); //RobotWin32.ShowWindow(telnet.MainWindowHandle, RobotWin32.ShowWindowEnum.ShowNormal); //IntPtr iHandle = RobotWin32.FindWindow(null, telnet.MainWindowTitle); RobotWin32.ShowWindow(putty.MainWindowHandle, RobotWin32.ShowWindowEnum.ShowNormal); var iHandle = RobotWin32.FindWindow(null, putty.MainWindowTitle); RobotWin32.SetForegroundWindow(iHandle); }
private void OpenForm(AccessObjectModel formToLoad, bool openInDesigner, MSAccess.Application application) { try { var formName = formToLoad.FullName ?? formToLoad.Name; application.DoCmd.OpenForm( formName, openInDesigner ? MSAccess.AcFormView.acDesign : MSAccess.AcFormView.acNormal ); var form = application.Forms[formName]; form.SetFocus(); RobotWin32.BringWindowToFront((IntPtr)form.Hwnd); } catch (Exception ex) { RobotMessageBox.Show(ex.Message); } }
private void ExecuteCode(AccessFormModel formModel, AccessControlModel control, string code) { if (code == "[Event Procedure]") { //form.SetFocus(); control.SetFocus(); RobotWin32.SetForegroundWindow((IntPtr)formModel.Hwnd); System.Windows.Forms.SendKeys.SendWait("{ENTER}"); } else if (!string.IsNullOrEmpty(code)) { application.DoCmd.RunMacro(code); } else { throw new Exception("Code to execute is empty"); } }
public static Process StartFormTester(string arguments) { string location = null;//TODO typeof(Robot.FormTester.G1ANTRobotFormTester).Assembly.Location; var process = Process.Start(location, arguments); while (process.MainWindowHandle == IntPtr.Zero) { System.Threading.Thread.Sleep(20); } process.WaitForInputIdle(); Thread.Sleep(5000); while (IsIconic(process.MainWindowHandle)) { RobotWin32.ShowWindow(process.MainWindowHandle, RobotWin32.ShowWindowEnum.Show); } process.WaitForInputIdle(); return(process); }
public void RelativeTest() { IntPtr hTesterAppWindow = testerApp.MainWindowHandle; RobotWin32.Rect windowRect = new RobotWin32.Rect(); RobotWin32.GetWindowRectangle(hTesterAppWindow, ref windowRect); int titleBarHeight = 24; scripter.Text = ($"ocrabbyy.processscreen area {SpecialChars.Text}0,0,{windowRect.Right - windowRect.Left},{titleBarHeight}{SpecialChars.Text} relative true"); scripter.Run(); int documentId = scripter.Variables.GetVariableValue <int>("result"); FineReaderDocument document = AbbyyManager.Instance.GetDocument(documentId); Assert.IsNotNull(document); string plainText = document.GetAllText(); Assert.IsTrue(plainText.Contains(appTitle)); }
public System.Windows.Rect GetRectangle() { object boundingRectNoDefault = automationElement.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty, true); if (boundingRectNoDefault != AutomationElement.NotSupported) { return((System.Windows.Rect)boundingRectNoDefault); } else if (automationElement.Current.NativeWindowHandle != 0) { RobotWin32.Rect rect = new RobotWin32.Rect(); IntPtr wndHandle = new IntPtr(automationElement.Current.NativeWindowHandle); if (RobotWin32.GetWindowRectangle(wndHandle, ref rect)) { return(new System.Windows.Rect(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top)); } } throw new NotSupportedException("Cannot get rectangle for that kind of UI element."); }
public void FindWindowTitleTest() { string appTitle = "TestApp"; Scripter scripter = new Scripter(); scripter.InitVariables.Clear(); System.Diagnostics.Process testerApp = null; List <GStruct.Structure> windowTitleRect = null; try { scripter = new Scripter(); scripter.InitVariables.Clear(); testerApp = AbbyTests.StartFormTester($"Title {appTitle}"); IntPtr hTesterAppWindow = testerApp.MainWindowHandle; RobotWin32.Rect windowRect = new RobotWin32.Rect(); RobotWin32.GetWindowRectangle(hTesterAppWindow, ref windowRect); int titleBarHeight = 24; scripter.Text = ($@"ocrabbyy.processscreen area {SpecialChars.Text}{windowRect.Left},{windowRect.Top},{windowRect.Right},{windowRect.Bottom}{SpecialChars.Text} ocrabbyy.find {SpecialChars.Text}{appTitle}{SpecialChars.Text} result {nameof(windowTitleRect)}"); scripter.Run(); windowTitleRect = scripter.Variables.GetVariableValue <List <GStruct.Structure> >(nameof(windowTitleRect)); Assert.AreNotEqual(0, windowTitleRect.Count); System.Drawing.Rectangle titleRect = ((GStruct.RectangleStructure)windowTitleRect[0]).Value; Assert.IsTrue(titleRect.Top > 0 & titleRect.Top < titleBarHeight, "Top edge position of found rectangle is incorrect"); Assert.IsTrue(titleRect.Bottom > 0 & titleRect.Bottom <= titleBarHeight, "Bottom edge position of found rectangle is incorrect"); Assert.IsTrue(titleRect.Left > 0 & titleRect.Left < 50, "Left edge position of found rectangle is incorrect"); Assert.IsTrue(titleRect.Right > 0 & titleRect.Right < windowRect.Right); } finally { if (testerApp != null && !testerApp.HasExited) { testerApp.Kill(); } } }
public void Execute(Arguments arguments) { if (arguments.Threshold.Value < 0 || arguments.Threshold.Value > 1) { throw new ArgumentOutOfRangeException("Threshold must be a value from 0 to 1."); } using (Bitmap bitmap1 = Imaging.OpenImageFile(arguments.Image.Value, nameof(arguments.Image))) { int timeout = (int)arguments.Timeout.Value.TotalMilliseconds; long start = Environment.TickCount; Rectangle foundRectangle = Rectangle.Empty; while (Math.Abs(Environment.TickCount - start) < timeout && Scripter.Stopped == false && foundRectangle == Rectangle.Empty) { using ( Bitmap bitmap2 = RobotWin32.GetPartOfScreen( Imaging.ParseRectanglePositionFromArguments(arguments.ScreenSearchArea.Value, arguments.Relative.Value), bitmap1.PixelFormat)) { foundRectangle = Imaging.IsImageInImage(bitmap1, bitmap2, (double)arguments.Threshold.Value); Application.DoEvents(); } } if (foundRectangle == Rectangle.Empty) { throw new TimeoutException("Image was not found in specified search area."); } else { Point foundPoint = (!arguments.CenterResult.Value) ? new Point(foundRectangle.X, foundRectangle.Y) : new Point(foundRectangle.X + foundRectangle.Width / 2, foundRectangle.Y + foundRectangle.Height / 2); foundPoint = new Point(foundPoint.X + arguments.OffsetX.Value, foundPoint.Y + arguments.OffsetY.Value); Scripter.Variables.SetVariableValue(arguments.Result.Value, new PointStructure(foundPoint)); } } }
public static Bitmap GetScreenshot(this RectangleStructure screenArea, BooleanStructure relative) { if (screenArea.Value.Width < 1 || screenArea.Value.Height < 1) { throw new ArgumentException("ScreenSearchArea argument's parts can't be negative. Both width and height must be bigger than zero."); } try { var screenSearchArea = screenArea.Value; if (relative.Value) { screenSearchArea = screenArea.Value.GetRelativeArea(); } return(RobotWin32.GetPartOfScreen(screenSearchArea, PixelFormat.Format24bppRgb)); } catch (Exception ex) { throw new Exception($"Could not get the screenshot image. Message: {ex.Message}", ex); } }