I am a newbie to Ahk and enthusiastic about your function and I believe it is a must-have for all users of Ahk. Your function was the first one I saw when I started learning ahk and I have been using it since version 6.0, thank you very much.
I use your function with a function of mine that integrates a kind of debug mode, that helps me find out if something goes wrong in the search... I have to complete it, but it is only one idea...
Code: Select all
DrawRectangle(x1:=0, y1:=0, w1:=0, h1:=0, n:=1, bw:=3, cl:="ff0000")
{
/*
flyingDman, RRR
Disegna la cornice di un rettangolo con l'uso di gui
*/
Global FirstCall
if ((w1=0) && (h1=0)) {
Gui % (n ": Destroy", FirstCall:=[])
Return
}
FirstCall? "": FirstCall:=[], FirstCall[n]? "": (FirstCall[n]:=[], FirstCall[n].1:=1)
, w1<0? (w1:=Abs(w1), x1:=x1-w1): "", h1<0? (h1:=Abs(h1), y1:=y1-h1): ""
Gui % n ": +LastFound"
w2:= w1 - bw, h2:= h1 - bw
WinSet, Region, 0-0 %w1%-0 %w1%-%h1% 0-%h1% 0-0 %bw%-%bw% %w2%-%bw% %w2%-%h2% %bw%-%h2% %bw%-%bw%
If (FirstCall[n].1) {
Gui % n ": -Caption +AlwaysOnTop +ToolWindow -DPIScale +HWNDhwnd +e0x8000088"
Gui % n ": Color", % cl
FirstCall[n].1:= 0
}
Gui % n ": Show", NA x%x1% y%y1% w%w1% h%h1% ; performs better then WinMove over some controls
}
CercaTesto(Text, ByRef Ok, Premi:=1, MaxCicliAttesa:=5, ShowMessage:=1, Param*)
{
/*
Text = stringa da ricercare data dalla funzione Findtext
Premi = 0 NON preme e NON sposta il mouse
1 Clicca e sposta il mouse sul testo trovato
-1 Mostra Mousetip e sposta il mouse alle coordinate trovate
-2 Mostra solo Mousetip sul testo trovato
MaxCicliAttesa = Massima Attesa prima di dare la ricerca fallita
ShowMessage = 0|1 : Mostra messaggio di Search
-1 : Mostra Area di ricerca e messaggio di Search
Return CercaTesto = 0|1 Testo trovato o non trovato
OK = Parametri della immagine trovata
========================================================================================================================================
If the return variable is set to 'ok', ok[1] is the first result found.
ok[1].id is the comment text, which is included in the <> of its parameter.
ok[1].1 is the X coordinate of the upper left corner of the found image
ok[1].2 is the Y coordinate of the upper left corner of the found image
ok[1].3 is the width of the found image
ok[1].4 is the height of the found image
ok[1].x <==> ok[1].1+ok[1].3//2 ( is the Center X coordinate of the found image )
ok[1].y <==> ok[1].2+ok[1].4//2 ( is the Center Y coordinate of the found image )
returnArray:=FindText(
OutputX:="" --> The name of the variable used to store the returned X coordinate
, OutputY:="" --> The name of the variable used to store the returned Y coordinate
, X1:=0 --> the search scope's upper left corner X coordinates
, Y1:=0 --> the search scope's upper left corner Y coordinates
, X2:=0 --> the search scope's lower right corner X coordinates
, Y2:=0 --> the search scope's lower right corner Y coordinates
, err1:=0 --> Fault tolerance percentage of text (0.1=10%)
, err0:=0 --> Fault tolerance percentage of background (0.1=10%)
, Text:="" --> can be a lot of text parsed into images, separated by '|'
, ScreenShot:=1 --> if the value is 0, the last screenshot will be used
, FindAll:=1 --> if the value is 0, Just find one result and return
, JoinText:=0 --> if you want to combine find, it can be 1, or an array of words to find
, offsetX:=20 --> Set the max text offset (X) for combination lookup
, offsetY:=10 --> Set the max text offset (Y) for combination lookup
, dir:=1 --> Nine directions for searching: up, down, left, right and center
, zoomW:=1 --> Zoom percentage of image width (1.0=100%)
, zoomH:=1 --> Zoom percentage of image height (1.0=100%)
)
The function returns an Array containing all lookup results,
any result is a object with the following values:
{1:X, 2:Y, 3:W, 4:H, x:X+W//2, y:Y+H//2, id:Comment}
If no image is found, the function returns 0.
All coordinates are relative to Screen, colors are in RGB format
If the return variable is set to 'ok', ok[1] is the first result found.
ok[1].id is the comment text, which is included in the <> of its parameter.
ok[1].1 is the X coordinate of the upper left corner of the found image
ok[1].2 is the Y coordinate of the upper left corner of the found image
ok[1].3 is the width of the found image
ok[1].4 is the height of the found image
ok[1].x <==> ok[1].1+ok[1].3//2 ( is the Center X coordinate of the found image ),
ok[1].y <==> ok[1].2+ok[1].4//2 ( is the Center Y coordinate of the found image ),
If OutputX is equal to 'wait' or 'wait1'(appear), or 'wait0'(disappear)
it means using a loop to wait for the image to appear or disappear.
the OutputY is the wait time in seconds, time less than 0 means infinite waiting
Timeout means failure, return 0, and return other values means success
If you want to appear and the image is found, return the found array object
If you want to disappear and the image cannot be found, return 1
Example 1: FindText(X:='wait', Y:=3, 0,0,0,0,0,0,Text) ; Wait 3 seconds for appear
Example 2: FindText(X:='wait0', Y:=-1, 0,0,0,0,0,0,Text) ; Wait indefinitely for disappear
*/
CoordMode, Tooltip, Screen
;~ MsgBox, % "Count= " . Param.Count()
;~ . "`nMaxIndex= " . Param.MaxIndex()
;~ . "`nMinIndex= " . Param.MinIndex()
;~ . "`nLength= " . Param.length()
If (!Param.Count()) {
; Parametri di default della zona di ricerca
;tollerranza 0 = 0.000001
Param := { x1:0
,y1:0
,x2:1920
,y2:1080
,tolleranza:0.1
,Appear:1}
}else if (Param.Count() < 6) {
Param.Appear := 1
}
pos1:=InStr(Text,"<")
pos2:=InStr(Text,">")
Commento:=SubStr(Text, Pos1+1,pos2-pos1-1)
x_tooltip:=Param.x1
y_tooltip:= (Param.y1>29) ? (Param.y1-29) : 0
;MouseMove,0,50,0,R
if(ShowMessage = -1 )
DrawRectangle(Param.x1, Param.y1, Param.x2-Param.x1, Param.y2-Param.y1, 1, 3, "red") ; Mostra Area di Ricerca
;ShowArrayInGui(Param)
if(Param.Appear = 1 ) {
Loop {
Switch ShowMessage
{
Case 0: ; NON Mostra niente
Case 1,-1: ; Mostra messaggi di stato
;MsgBox,% Param.x1 " " Param.y1
ToolTip,% "Search <" Commento ">... " A_Index "/" MaxCicliAttesa,% x_tooltip,% y_tooltip,20
;Sleep,5000
Default:
}
;ok:=FindText(Param.x1, Param.y1, Param.x2, Param.y2, Param.tolleranza, Param.tolleranza, Text)
ok:=FindText(OutputX,OutputY,Param.x1, Param.y1, Param.x2, Param.y2, Param.tolleranza, Param.tolleranza, Text)
Sleep, 1000
} until (ok) or (A_Index = MaxCicliAttesa)
if(ShowMessage=-1)
DrawRectangle(0, 0, 0, 0, 1, 3, "red") ; Cancella Area di Ricerca
if(ShowMessage!=0)
ToolTip,,,,20 ; Cancella Tooltip di ricerca
if (ok) {
Switch Premi
{
Case -2: ; Mostra Mousetip alle coordinate trovate
X:=ok.1.1, Y:=ok.1.2, W:=ok.1.3, H:=ok.1.4, Comment:=ok.1.id, X+=W//2, Y+=H//2
FindText().MouseTip(ok[1].x, ok[1].y)
Case -1: ; Mostra Mousetip e sposta il mouse alle coordinate trovate
X:=ok.1.1, Y:=ok.1.2, W:=ok.1.3, H:=ok.1.4, Comment:=ok.1.id, X+=W//2, Y+=H//2
FindText().MouseTip(ok[1].x, ok[1].y)
Click, %X%, %Y%, 0
Case 0: ; NON preme e non sposta il mouse
Case 1: ; Clicca e sposta il mouse sulle coordinate trovate
X:=ok.1.1, Y:=ok.1.2, W:=ok.1.3, H:=ok.1.4, Comment:=ok.1.id, X+=W//2, Y+=H//2
Click, %X%, %Y%
Sleep, 1000
Default:
}
return 1
}else{
if(ShowMessage!=0) {
loop,1
SoundBeep
ToolTip,% "<" Commento "> NON TROVATO !!!",% x_tooltip,% y_tooltip,20
Sleep, 3000
ToolTip,,,,20
}
;MsgBox, % Commento " [ NON trovato!!! ]"
;ExitApp
return 0
}
}else if(Param.Appear = 0 ) {
}else{
}
}