chaoscreater wrote: ↑06 Apr 2021, 16:19
...
Also, if you don't limit the capture to a specific region/area, it'll perform slow. All my Findtext has the coordinates of the captured area and this will be different on machines with different resolutions.
If you set up your script correctly with a common set of global variables and/or write your own functions that simply call and make use of FindText, you can get pretty good results. WinGetPos is your friend to help narrow your search area to the Window's area only. On my function I wrote for using FindText to search and click for automation purposes, I have an "area" parameter where I can specify: "top" "left" "right" "bottom" "center" "topleft" "topright" "bottomleft" " bottomright" "top 1/4" "left 1/9" etc to speed up execution beyond only limiting to the window's search area.
Here is what I use in case it helps anyone in here (my workstation uses 3 monitors, but I am trying to make my script somewhat universal / distributable for those who work my same position at my company, but may be on slightly different hardware setups):
Code: Select all
SYS_WinClickTarget(WinName, Target, Xoff:=0, Yoff:=0, Mspd:=0, TXT_ERR:=0, BG_ERR:=0, Zone:="", ClickAll:=0, WhichButton:="")
{
global TLX, TLY, BRX, BRY, H, W, Numerator, Denominator, X, Y
SetTitleMatchMode, 2
SetTitleMatchMode, Fast
SetDefaultMouseSpeed, %Mspd%
WinGetPos, TLX, TLY, W, H, %WinName%
BRX:= TLX + W
BRY:= TLY + H
;MsgBox, INITIAL`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
if (Zone != "")
SYS_WinGetZone(Zone) ; THIS SETS THE GLOBAL VARS: TLX, TLY, BRX, BRY, Numerator, Denominator
;MsgBox, POST-PROCESSING`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
if (ClickAll == 0 && ok:=FindText(TLX, TLY, BRX, BRY, TXT_ERR, BG_ERR, Target))
{
CoordMode, Mouse
X:=ok.1.x + Xoff, Y:=ok.1.y + Yoff, Comment:=ok.1.id
if (WhichButton != "")
Click, %X%, %Y%, %WhichButton%
else
Click, %X%, %Y%
}
else if (ClickAll == 1 && ok:=FindText(TLX, TLY, BRX, BRY, TXT_ERR, BG_ERR, Target))
{
CoordMode, Mouse
for i,v in ok
if (i<=ok.MaxIndex())
{
X:=ok[i].x + Xoff, Y:=ok[i].y + Yoff, Comment:=ok[i].id
if (WhichButton != "")
Click, %X%, %Y%, %WhichButton%
else
Click, %X%, %Y%
}
}
else if (ClickAll == -1 && ok:=FindText(TLX, TLY, BRX, BRY, TXT_ERR, BG_ERR, Target))
{
CoordMode, Mouse
for i,v in ok
if (i<=ok.MaxIndex())
{
X:=ok[i].x + Xoff, Y:=ok[i].y + Yoff, Comment:=ok[i].id
MouseMove, %X%, %Y%
}
}
}
Code: Select all
SYS_WinGetZone(str)
{
global TLX, TLY, BRX, BRY, H, W, Numerator, Denominator
ZoneArray:= StrSplit(str, A_SPACE)
Zone:= ZoneArray[1]
Frac:= ZoneArray[2]
if (Frac != "")
{
Fraction:= StrSplit(Frac,"/")
Numerator:= Fraction[1]
Denominator:= Fraction[2]
}
;MsgBox, Zone=%Zone% `nFrac=%Frac% `nNumer:%Numerator% `nDenom:%Denominator%
if (Zone = "TOP" || Zone = "T")
{
TLX:= TLX, TLY:= TLY
;MsgBox, TOP`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
if (Frac != "")
{
BRX:= TLX + W
BRY:= TLY + (H / Denominator)
;MsgBox, TOP-MOD`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
}
;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
}
else if (Zone = "LEFT" || Zone = "L")
{
TLX:= TLX, TLY:= TLY
;MsgBox, LEFT`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
if (Frac != "")
{
BRX:= TLX + (W / Denominator)
BRY:= TLY + H
;MsgBox, LEFT-MOD`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
}
;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
}
else if (Zone = "BOTTOM" || Zone = "B")
{
BRX:= TLX + W, BRY:= TLY + H
;MsgBox, BOTTOM`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
if (Frac != "")
{
TLX:= TLX
TLY:= (TLY + H) - (H / Denominator)
;MsgBox, BOTTOM-MOD`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
}
;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
}
else if (Zone = "RIGHT" || Zone = "R")
{
BRX:= TLX + W, BRY:= TLY + H
;MsgBox, RIGHT`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
if (Frac != "")
{
TLX:= (TLX + W) - (W / Denominator)
TLY:= TLY
;MsgBox, RIGHT-MOD`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
}
;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
}
else if (Zone = "TOPLEFT" || Zone = "TL")
{
TLX:= TLX, TLY:= TLY, BRX:= TLX + ((1/4) * W), BRY:= TLY + ((1/4) * H)
;MsgBox, TOPLEFT`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
}
else if (Zone = "BOTTOMLEFT" || Zone = "BL")
{
TLX:= TLX, TLY:= TLY + ((3/4) * H), BRX:= TLX + ((1/4) * W), BRY:= TLY + H
;MsgBox, BOTTOMLEFT`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
}
else if (Zone = "BOTTOMRIGHT" || Zone = "BR")
{
TLX:= TLX + ((3/4) * W), TLY:= TLY + ((3/4) * H), BRX:= TLX + W, BRY:= TLY + H
;MsgBox, BOTTOMRIGHT`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
}
else if (Zone = "TOPRIGHT" || Zone = "TR")
{
TLX:= TLX + ((3/4) * W), TLY:= TLY, BRX:= TLX + W, BRY:= TLY + ((1/4) * H)
;MsgBox, TOPRIGHT`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
}
else if (Zone = "CENTER" || Zone = "CTR")
{
TLX:= TLX + ((1/3) * W), TLY:= TLY + ((1/3) * H), BRX:= TLX + ((2/3) * W), BRY:= TLY + ((2/3) * H)
;MsgBox, CENTER`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
}
}
It is coded pretty primitively and not very efficiently as I work on this in between answering calls at my day job, lol. (I automate as much as possible of our Citrix-based apps that stream from a remote machine completely optically using FindText and keyboard macros alone.) Major thanks to
@feiyue and his algorithms that deal with streaming artifacts so well! Also, I have noticed that FindText v8.4 runs faster and more consistently than the v7.7 I was previously using.