FindText - Capture screen image into text and then find it

Post your working scripts, libraries and tools for AHK v1.1 and older
maxkill
Posts: 158
Joined: 11 Apr 2016, 13:03

Re: FindText - Capture screen image into text and then find it

Post by maxkill » 21 Jul 2022, 19:57

SteveMylo wrote:
21 Jul 2022, 19:23
maxkill wrote:
21 Jul 2022, 13:17
not really sure how to save the x coordinates from the middle of images
The answer is right there in front of you in my script.
The middle of the x coordinates is ((ok[1].x + ok[2].x) / 2).
So if you don't want a messy X value, then create a Variable. middleX := ((ok[1].x + ok[2].x) / 2)
*Also note that the X & Y in the below code if (ok:=FindText(X, Y, 0, 0, A_ScreenWidth, A_ScreenHeight, 0, 0, Text)) is the position of the 1st image found. Which in this case you don't need.
** Also with the new FindTEXT function you have, you don't need this clutter ===> xx:=ok.1.1, yy:=ok.1.2, w:=ok.1.3, h:=ok.1.4

Code: Select all

q::
MouseGetPos, xx, yy
Text:="|<>*imgtext1----"
Text.="|<>*imgtext2----"
if (ok:=FindText(X, Y, 0, 0, A_ScreenWidth, A_ScreenHeight, 0, 0, Text))  ; <== you can (Plus + or Minus -) anything from the search range as you know, e.g. (A_ScreenHeight /2)  or (A_ScreenHeight - yy) etc etc. You get the gist obviously. 
 ;~  ====> (pasted here just for reference)  ====>   MouseClick, Left, ((ok[1].x + ok[2].x) / 2), ((ok[1].y + ok[2].y ) / 2), 1, 1 
middleX := ((ok[1].x + ok[2].x) / 2)  
{
	MouseMove, middleX, yy, 1
}
return
Thanks a lot it works now even better than the old script because it's more exact so perfect!

Only thing strange for me about the Include function (as apposed to having all code in one script) is I am infact getting a noticable lagg on certain scripts. The one you provided was fast and nice, but on others I get a delay on for some reason. Is it faster if I put the findtext file in this lib folder somehow?
Last edited by maxkill on 22 Jul 2022, 12:57, edited 1 time in total.

User avatar
SteveMylo
Posts: 233
Joined: 22 Jun 2021, 00:50
Location: Australia
Contact:

Re: FindText - Capture screen image into text and then find it

Post by SteveMylo » 22 Jul 2022, 04:36

I don’t know why you’re getting lag. I never have.
But yeah , i just put the FindText function in Autohotkey’s Lib Folder and that’s it. And because it’s there, you don’t even have to add #include <FindText> At the top of your script cause Autohotkey will automatically find it.
Make sure you haven’t created Findtext.ahk in any other lib folder cause it may search there & might be an old FindText Function. Delete all others & just keep the newest one in the main Lib Folder. Job done 👌

maxkill
Posts: 158
Joined: 11 Apr 2016, 13:03

Re: FindText - Capture screen image into text and then find it

Post by maxkill » 22 Jul 2022, 08:57

@SteveMyloI don't have a lib folder, can I just create a folder called lib in the ahk folder? The ahk I have is from 202105 it seems

User avatar
SteveMylo
Posts: 233
Joined: 22 Jun 2021, 00:50
Location: Australia
Contact:

Re: FindText - Capture screen image into text and then find it

Post by SteveMylo » 22 Jul 2022, 15:49

I’ve only been using AHK for a year so I’m
Probably not the best person to ask.
Why don’t you just download the latest AHK?
I would have assumed that any version has a Lib folder in the main Autohotkey folder. Anywas doesn’t matter I guess.
You can just paste the path infront of the #include file

maxkill
Posts: 158
Joined: 11 Apr 2016, 13:03

Re: FindText - Capture screen image into text and then find it

Post by maxkill » 22 Jul 2022, 17:49

SteveMylo wrote:
22 Jul 2022, 15:49
Roger that, thanks for all!

maxkill
Posts: 158
Joined: 11 Apr 2016, 13:03

Re: FindText - Capture screen image into text and then find it

Post by maxkill » 23 Jul 2022, 14:00

Guys, how can I search for one image and if not found it looks for next image? I tried searching for over 1 hour but found only merging of image search etc which I can't tell how to apply
here's what I tried ....

Code: Select all

MouseGetPos, aX, aY
Mousegetpos, xx, yy

Text:="|<>*imgtext1"
Text:="|<>*imgtext2"


if (ok:=FindText(xx-2500, yy+2400, xx, yy, 0, 0, Text)) ; 150 can be adjusted by yourself
{
 xx:=ok.1.1, yy:=ok.1.2, w:=ok.1.3, h:=ok.1.4
 mousemove, xx, aY+0
click left
}
Doesn't work :headwall:

edit; lol just happened to find it
Descolada wrote:
29 Mar 2022, 23:26
thaihoa3189 wrote:
29 Mar 2022, 20:36
SteveMylo wrote:
29 Mar 2022, 02:23
thaihoa3189 wrote:
23 Mar 2022, 22:24
Can someone make a full function youtube tutorial video for this FindText class please? :thumbup:
I only have different ways to incorporate different mouse clicks on this thread. viewtopic.php?p=441482#p441482
I want to do a video tutorial but sorry paid work comes 1st. One day maybe. Took me months to learn FindText Function Properly
Many thanks for your guide. It is very useful to me. While waiting for your next instruction I have 1 question. That is whether the FindText function can find multiple text in a command or not. Like : FindText(X, Y, 0, 0, 1366, 768, 0, 0, Text1|Text2|Text3). If it is possible what is the correct syntax of it? :)
You got it pretty much right. "|<Text1>**50$5.Tb3klz|<Text2>**50$5.Tb3klz" is the correct syntax and will return a match for either Text1 or Text2 (if FindAll is set to 0) or all matches for either Text1 or Text2 (if FindAll is set to 1).
These will also work:

Code: Select all

Text1 := "|<Text1>**50$5.Tb3klz"
Text2 := "|<Text2>**50$5.Tb3klz"
FindText(X, Y, 0, 0, 1366, 768, 0, 0, Text1 . Text2)

Code: Select all

Text := "|<Text1>**50$5.Tb3klz"
Text .= "|<Text2>**50$5.Tb3klz"
FindText(X, Y, 0, 0, 1366, 768, 0, 0, Text)
my code works now

Code: Select all

Text1:="|<>*imgtext1"
Text2:="|<>*imgtext2"


if (ok:=FindText(xx-1500, yy+2400, xx, yy, 0, 0, Text1 . Text2)) ; 150 can be adjusted by yourself
{
  xx:=ok.1.1, yy:=ok.1.2, w:=ok.1.3, h:=ok.1.4
  mousemove, xx, aY+0
click left
}
Last edited by maxkill on 23 Jul 2022, 14:19, edited 1 time in total.

Descolada
Posts: 1101
Joined: 23 Dec 2021, 02:30

Re: FindText - Capture screen image into text and then find it

Post by Descolada » 23 Jul 2022, 14:15

@maxkill, it doesn't work because you are overwriting your Text: Text:="|<>*imgtext2" overwrites Text:="|<>*imgtext1"
Either use Text:="|<>*imgtext1|<>*imgtext2", or use the "append" command .= instead of :=:

Code: Select all

Text:="|<>*imgtext1"
Text.="|<>*imgtext2"

maxkill
Posts: 158
Joined: 11 Apr 2016, 13:03

Re: FindText - Capture screen image into text and then find it

Post by maxkill » 23 Jul 2022, 14:24

Descolada wrote:
23 Jul 2022, 14:15
@maxkill, it doesn't work because you are overwriting your Text: Text:="|<>*imgtext2" overwrites Text:="|<>*imgtext1"
Either use Text:="|<>*imgtext1|<>*imgtext2", or use the "append" command .= instead of :=:

Code: Select all

Text:="|<>*imgtext1"
Text.="|<>*imgtext2"
Thanks I tried it and it works too by just doing the first one := then the others below it .= and code like normal, nice, thanks!

maxkill
Posts: 158
Joined: 11 Apr 2016, 13:03

Re: FindText - Capture screen image into text and then find it

Post by maxkill » 23 Jul 2022, 15:09

@DescoladaDo you have any idea why an image overrides another sometimes? It does this on occation, where even if one image is found and is closer it still goes to the other image.
Can you put some sort of if both images are present go to the one closest to mousepointer option or some other solution to this?

User avatar
SteveMylo
Posts: 233
Joined: 22 Jun 2021, 00:50
Location: Australia
Contact:

Re: FindText - Capture screen image into text and then find it

Post by SteveMylo » 23 Jul 2022, 16:15

@maxkill maxy, Find text doesn’t randomly skip the 1st image. It just means your Text string is wrong or not perfect & it can’t find it.
FindText can’t search from the mouse outwards (i wish it could) without formulating your own code.
But you CAN change the search direction which helps a lot to get it to find certain images 1st.
I’ve already given you a ‘Change Search Direction’ Before. If this is what you’re after then Please make sure you do a thorough search before asking. If not then all good 🖖
I’ll paste from page ‘40’ below about search Direction.
===============================
Here is how you change the search Direction.

Text:="|<GREEN>[email protected]$6.SzzzzSU"
if (ok:=FindText(X, Y, 0, 0, 1920, 1080, 0, 0, Text,,,,,,1))

After the 6 commas,,,,,, that is after the variable "Text", change the "1" to change SEARCH Direction. e.g. if (ok:=FindText(X, Y, 0, 0, 1920, 1080, 0, 0, Text,,,,,,6))
Also note, if your search range is 4 (0's) this actually represents search entire monitor screen. if (ok:=FindText(X, Y, 0, 0, 0, 0, 0, 0, Text,,,,,,1))
But if you choose search from the centre outwards which is Number '9', then you can't have 4 '0's' , you must have a proper search range e.g. if (ok:=FindText(X, Y, 0, 0, 1920, 1080, 0, 0, Text,,,,,,9))


1 = Starts Top Left & Scans Right. then it scans again from 1 Pixel down from the Top Left and it scans Right again etc. etc.

2 = TR - Scan L
3 = BL Scan R
4 = BR scan L
5 = TL Scan D
6 = BL - Scan U
7 = TR Scan D
8 = BR scan U
9 = Starts at the Centre and scans outward in a circle clockwise I think.

maxkill
Posts: 158
Joined: 11 Apr 2016, 13:03

Re: FindText - Capture screen image into text and then find it

Post by maxkill » 23 Jul 2022, 17:18

@SteveMylo
Well it does actually find that image that was skipped if I move the mouse further from the image so the other image can't be found, then it finds it but if both images can be found it defaults to the furthest away for some reason I'm not sure why. Thanks for your direction explanations, although I already search a defined area
if (ok:=FindText(xx-1500, yy+2400, xx, yy, 0, 0, Text)) ; 150 can be adjusted by yourself
Last edited by maxkill on 23 Jul 2022, 17:50, edited 1 time in total.

User avatar
SteveMylo
Posts: 233
Joined: 22 Jun 2021, 00:50
Location: Australia
Contact:

Re: FindText - Capture screen image into text and then find it

Post by SteveMylo » 23 Jul 2022, 17:30

Oh ok. All your doing is searching in a range relative to your mouse, which is fine if that’s what you want.
Although search range has nothing to do with search direction if both images are in the search range.
I find all you need is ‘defining the search DIRECTION’ mixed in with ‘Defining which occurrence in the array to go to’ e.g. ok[2].x
These two combined works magic.
But hey, if you need to search relative to the mouse then all good.

maxkill
Posts: 158
Joined: 11 Apr 2016, 13:03

Re: FindText - Capture screen image into text and then find it

Post by maxkill » 23 Jul 2022, 17:56

@SteveMyloThanks for response Steve.
I see I thought it started closest to mouse (or was supposed to working outwords) for some reason. Did you mean I should put in another command for this like ok[2].x where do I put this command exactly?

User avatar
SteveMylo
Posts: 233
Joined: 22 Jun 2021, 00:50
Location: Australia
Contact:

Re: FindText - Capture screen image into text and then find it

Post by SteveMylo » 23 Jul 2022, 18:33

I’ve already explained when & how to use ok[2].x etc. it’s actually useless if there is only one matching image. It’s only if there is more than one exact image in your single text string search.

maxkill
Posts: 158
Joined: 11 Apr 2016, 13:03

Re: FindText - Capture screen image into text and then find it

Post by maxkill » 23 Jul 2022, 22:34

@SteveMylo
Okay hmm then I don't know. Thanks

manjyomethunder
Posts: 6
Joined: 06 Feb 2021, 11:15

Re: FindText - Capture screen image into text and then find it

Post by manjyomethunder » 03 Aug 2022, 03:10

hello, may i know how can i combine this code in a loop
i want a function like this
it will auto click the text Available whenever it is pop up in the page, then click Home, then click Save edits

Code: Select all

F1::
Loop
{
  Sleep, 22
if ok:=FindText(779,554,150000,150000,0,0,"|<available>*182$56.6001a0M301k009U60k0w000M1UA0DAPtayTnDXNanNgrirRaNjqPxlhzTqnxazMPTrwxnNwr6q33CRqTRvhnkPXxazTnDc")
FindText_Left_Click(Ok,X_Adj:=0,Y_Adj:=0,MoveBack:=0)
;Sleep, 100
;Send, {Home}
Sleep, 50
;MouseMove, 1378, 624
}

Return
F2::
Send, {Home}
MouseMove, 1378, 624
;if ok:=FindText(1181,639,150000,150000,0,0,"|<save shifts>*160$69.kTzzzzzyDllw1zzzzzzlyAA27zzzzzyDtX0ssttlzllD803w0C07w20E043U0k0T0E000k8s61XsGC1X7UU000DUFkAM700U03y0C1X0s646AT61kAM000kk3s0C1X41U670zUFkAQsS9twDy7DNbo")
;FindText_Left_Click(Ok,X_Adj:=0,Y_Adj:=0,MoveBack:=0)
return
what i am doing now with my current code is
i click F1, then that is on the loop, then when the text Available pop up, it will auto click, then i will press F2 to scroll to the top of page then mousemove then i click Save shift

because when i try to combine this, and press F1, it will trigger the scroll top(Home) and mousemove coordinates.

thanks.

User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: FindText - Capture screen image into text and then find it

Post by iilabs » 07 Aug 2022, 11:12

Hi feiyue,

Amazing program! I was wondering if you can help me with the OCR example and building an array of what is found.

Ive tried the above code as well as your example from first page regarding the OCR. I am unable to make an array and was wondering if I'm doing something wrong?
I have FindText.ahk included in my library.

Code: Select all

!j::
t1:=A_TickCount
t1:=A_TickCount, Text:=X:=Y:=""

Text:="|<0.>*132$23.zzzzzzzzzzzzk7zz07zw07zky7z3y7y7wDwDsTsTkzkzVzVz3z3y7y7wDwDsTsTkzkzVzVz3X1w77VsyDU3wTU7szzzzzzzz"
Text:="|<0.2>*120$69.zzzzzzzzzzzzzzjzzzzzzzzzzzzzzs3zzU3zzzzzy0Dzw0DzzzzzU0zy00zzzzzsT3zkz3zzzzy7wDy7wDzzzzkzVztzVzzzzy7wDzzwC007zkzVzzzVk00zy7wDzzsDzzzzkzVzzz7zzzzy7wDzzVzzzzzkzVzzwDzzzzy7wDzy7y007zkzVzzUzk00zy7wDzwDzzzzzkzVly7zzzzzy3sCDUzzzzzzwD7lwDzzzzzzk1yC00Dzzzzz0Dlk01zzzzzzzzzzzw"
Text.="|<0.2>*127$68.zzzzzzzzzzzzzzzzw1zzk1zzzzzy0Dzw0Dzzzzz01zw7VzzzzzVwDz3wDzzzzkzVzkzVzzzzwDsTyTsTzzzz3y7zzy6007zkzVzzzVU01zwDsTzzkTzzzz3y7zzwTzzzzkzVzzwDzzzzwDsTzz3zzzzz3y7zzXy007zkzVzzVzU01zwDsTzszzzzzz3y77sTzzzzzsT1lw7zzzzzz3lwT3zzzzzzs0z7007zzzzz0Dlk01zzzzzzzzzzzs"
Text.="|<0.>*132$23.zzzzzzzzzzzzk7zz07zw07zky7z3y7y7wDwDsTsTkzkzVzVz3z3y7y7wDwDsTsTkzkzVzVz3X1w77VsyDU3wTU7szzzzzzzz"

ok:=FindText(0, 0, A_ScreenWidth, A_ScreenHeight, 0,0,Text)
;FindText().MouseTip(X, Y)   ;works
arr:=FindText.OCR(ok), OCR:=arr.text  ;doesnt work
;msgbox, %OCR%  
msgbox, %  ok[1].id  ;works
Return
'

Descolada
Posts: 1101
Joined: 23 Dec 2021, 02:30

Re: FindText - Capture screen image into text and then find it

Post by Descolada » 07 Aug 2022, 11:34

@iilabs, I'm not feiyue, but perhaps I can give some input...

1.

Code: Select all

Text:="|<0.>*132$23.zzzzzzzzzzzzk7zz07zw07zky7z3y7y7wDwDsTsTkzkzVzVz3z3y7y7wDwDsTsTkzkzVzVz3X1w77VsyDU3wTU7szzzzzzzz"
Text:="|<0.2>*120$69.zzzzzzzzzzzzzzjzzzzzzzzzzzzzzs3zzU3zzzzzy0Dzw0DzzzzzU0zy00zzzzzsT3zkz3zzzzy7wDy7wDzzzzkzVztzVzzzzy7wDzzwC007zkzVzzzVk00zy7wDzzsDzzzzkzVzzz7zzzzy7wDzzVzzzzzkzVzzwDzzzzy7wDzy7y007zkzVzzUzk00zy7wDzwDzzzzzkzVly7zzzzzy3sCDUzzzzzzwD7lwDzzzzzzk1yC00Dzzzzz0Dlk01zzzzzzzzzzzw"
Text.="|<0.2>*127$68.zzzzzzzzzzzzzzzzw1zzk1zzzzzy0Dzw0Dzzzzz01zw7VzzzzzVwDz3wDzzzzkzVzkzVzzzzwDsTyTsTzzzz3y7zzy6007zkzVzzzVU01zwDsTzzkTzzzz3y7zzwTzzzzkzVzzwDzzzzwDsTzz3zzzzz3y7zzXy007zkzVzzVzU01zwDsTzszzzzzz3y77sTzzzzzsT1lw7zzzzzz3lwT3zzzzzzs0z7007zzzzz0Dlk01zzzzzzzzzzzs"
Text.="|<0.>*132$23.zzzzzzzzzzzzk7zz07zw07zky7z3y7y7wDwDsTsTkzkzVzVz3z3y7y7wDwDsTsTkzkzVzVz3X1w77VsyDU3wTU7szzzzzzzz"
Here your second line overwrites the first (unless you meant to?). The second line should be Text.=

2. In the part arr:=FindText.OCR(ok), it should be arr:=FindText().OCR(ok)

3. Your error margins are set to 0, so some of your text might not be found. Try using 0.1 for both error margins.

User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: FindText - Capture screen image into text and then find it

Post by iilabs » 07 Aug 2022, 11:40

Ok will try that Descolada. Thanks for jumping in. You have helped me tremendously on other obstacles so really appreciate your time. I will give this a try. I noticed that there is addition to the findtext() with a findtext.ocr() in this post. Should I also add this to the library?

Descolada
Posts: 1101
Joined: 23 Dec 2021, 02:30

Re: FindText - Capture screen image into text and then find it

Post by Descolada » 07 Aug 2022, 12:05

@iilabs, I'm not sure I understood what you want to add to the library. I am using FindText version 8.9 library, and no FindText methods work with FindText.method (without parenthesis after FindText), only FindText().method works (WITH parenthesis). For example FindText.MouseTip(ok.1.x, ok.1.y) does nothing, whereas FindText().MouseTip(ok.1.x, ok.1.y) works. Perhaps feiyue's example OCR script was made using an older version of the library?

Post Reply

Return to “Scripts and Functions (v1)”