The following procedure searches for the Paste button within an active window. If the button is found, the procedure “clicks” it; otherwise it inserts a warning message into the test log.
JavaScript
function TestProc()
{
let w = Sys.Desktop.ActiveWindow();
let Rect = Regions.FindRegion("Paste_bmp", w);
if (!strictEqual(Rect, null))
Sys.Desktop.ActiveWindow().Click(Rect.Left + Rect.Width/2, Rect.Top + Rect.Height/2);
else
Log.Warning("Not found");
}
JScript
function TestProc()
{
var w = Sys.Desktop.ActiveWindow();
var Rect = Regions.FindRegion("Paste_bmp", w);
if (Rect != null)
Sys.Desktop.ActiveWindow().Click(Rect.Left + Rect.Width/2, Rect.Top + Rect.Height/2);
else
Log.Warning("Not found");
}
Python
def TestProc():
w = Sys.Desktop.ActiveWindow()
Rect = Regions.FindRegion("Paste_bmp", w)
if (Rect != None):
Sys.Desktop.ActiveWindow().Click(Rect.Left + Rect.Width/2, Rect.Top + Rect.Height/2)
else:
Log.Warning("Not found")
VBScript
Sub TestProc
Dim w, Rect
Set w = Sys.Desktop.ActiveWindow
Set Rect = Regions.FindRegion("Paste_bmp", w)
If Not Rect Is Nothing Then
Call Sys.Desktop.ActiveWindow.Click(Rect.Left + Rect.Width/2, Rect.Top + Rect.Height/2)
Else
Log.Warning "Not found"
End If
End Sub
DelphiScript
procedure TestProc;
var w, Rect;
begin
w := Sys.Desktop.ActiveWindow;
Rect := Regions.FindRegion('Paste_bmp', w);
if Rect <> nil then
Sys.Desktop.ActiveWindow.Click(Rect.Left + Rect.Width/2, Rect.Top + Rect.Height/2)
else
Log.Warning('Not found');
end;
C++Script, C#Script
function TestProc()
{
var w = Sys["Desktop"]["ActiveWindow"]();
var Rect = Regions["FindRegion"]("Paste_bmp", w);
if (Rect != null)
Sys["Desktop"]["ActiveWindow"]()["Click"](Rect["Left"]+ Rect["Width"]/2, Rect["Top"] + Rect["Height"]/2);
else
Log["Warning"]("Not found");
}
See Also
Find Method
FindRegion Method
Finding an Image Within Another Image