FindText - Capture screen image into text and then find it

Post your working scripts, libraries and tools for AHK v1.1 and older
malbec299
Posts: 1
Joined: 15 May 2020, 07:55

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

15 May 2020, 08:15

rinjp727 wrote:
10 May 2020, 06:17
OMGmarc wrote:
28 Apr 2020, 09:18
endgame94 wrote:
27 Apr 2020, 23:08
I downloaded and compile it into an exe file. But when running the exe file, nothing happens! The program does not appear! Please everyone help@@
You don't need to compile the FindText.ahk Just run the script itself.

Steps:
1. Copy the code from the OP.
2. Paste it into a blank text file.
3. Save the text file as FindText.ahk.
4. Double click on FindText.ahk to launch FindText.

et voila, start capturing and saving text strings.
>"C:\Program Files\AutoHotkey\SciTE\..\AutoHotkey.exe" /ErrorStdOut "C:\Users\admin\Desktop\FindText.ahk"
C:\Users\admin\Desktop\FindText.ahk (71) : ==> This line does not contain a recognized action.
Specifically: local
>Exit code: 2 Time: 0.1478
Please help me.!!!

any solution to this problem?

I have the same problem
gregster
Posts: 8886
Joined: 30 Sep 2013, 06:48

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

15 May 2020, 08:22

malbec299 wrote:
15 May 2020, 08:15
rinjp727 wrote:
10 May 2020, 06:17
>"C:\Program Files\AutoHotkey\SciTE\..\AutoHotkey.exe" /ErrorStdOut "C:\Users\admin\Desktop\FindText.ahk"
C:\Users\admin\Desktop\FindText.ahk (71) : ==> This line does not contain a recognized action.
Specifically: local
>Exit code: 2 Time: 0.1478
Please help me.!!!

any solution to this problem?

I have the same problem
Did you check your AHK version? It might be too old. Force-local mode was introduced in AHK v1.1.27.
gregster wrote:
10 May 2020, 09:46
rinjp727 wrote:
10 May 2020, 06:17
>"C:\Program Files\AutoHotkey\SciTE\..\AutoHotkey.exe" /ErrorStdOut "C:\Users\admin\Desktop\FindText.ahk"
C:\Users\admin\Desktop\FindText.ahk (71) : ==> This line does not contain a recognized action.
Specifically: local
>Exit code: 2 Time: 0.1478
Please help me.!!!
Could hint to an AHK version that is too old.
paulpma
Posts: 65
Joined: 08 Sep 2018, 22:05

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

15 May 2020, 09:18

I know FindText has Screen Shot feature, but I am not sure how to use it the following scenario.. I need screenshot to be taken so the window can be closed (important) then FindText work on the screen shot that was taken before window was closed. Is this possible? I have seen BindWindow and BindWindow+ feature, but to my knowledge they can be used only if window still open?

Code: Select all

SetTitleMatchMode, 2
id:=WinExist("Themes ahk_class CabinetWClass")
FindText_BindWindow(id)  ; Unbind Window using FindText_BindWindow(0)
Or ideally be able to use pBitmap generated by GDIP library, and use it with FindText?

One may wonder why? 15inch monitor... and need to multitask while FindText helps is the process..

@chaoscreater : re modifying string --- it can be modified only during capturing process. look for "modify" checkbox, then click on each individual pixel.

Thank you.
andy5566888
Posts: 10
Joined: 07 May 2020, 02:20

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

17 May 2020, 21:40

@rommmcek how to get like Text :="|<>*196$20.0zk0zz0w1wC0777stVz6kzlw6wT0DDk7rw3tz0w7kD1y3URUw6QD3XXVkzVw3zw0Dw2" or this Text is mean what?
User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

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

18 May 2020, 03:20

"Text" is just a variable containing an encoded image snippet. You can get it with Capture Image … tool. Run FindText.ahk click Capture then position the frame with the mouse, right click once and again. Then click Gray2Two then Auto and if you lucky OK. Of course you could additionally trim the image with buttons around Auto before you click OK if needed.
Attachments
Capture Img.png
Capture Img.png (91.12 KiB) Viewed 4009 times
andy5566888
Posts: 10
Joined: 07 May 2020, 02:20

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

18 May 2020, 22:46

@rommmcek oh thx now i know this code can do what
reverberation
Posts: 314
Joined: 13 Dec 2015, 20:48

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

20 May 2020, 21:09

Hello,

I'm new to this function, appreciate if anyone can help me out here. I am using FindText to find a small arrow button in Evernote, so that the Reminders list will be open.

The msgbox says successful and the box highlighted the correct position, but it wasn't clicked on. Why is that so / what am I doing wrong ?

Thanks!

Code: Select all

; Run Title Search Evernote using Ctrl+Win+3
#Include FindText.ahk
^#3::
IfWinExist ahk_class ENMainFrame
	WinActivate
else
	Run C:\Program Files (x86)\Evernote\Evernote.exe
	Sleep 1000
	SendInput {f9}
	SendInput ^!f
	Sleep 100
	SendInput {tab}{home} ;scroll to top of notes
	Sleep 50

		 
		 t1:=A_TickCount, X:=Y:=""

Text:="|<ReminderButton>**50$15.000400k0500Y04E0W04U0c0600U000U"

 if (ok:=FindText(271-150000, 230-150000, 271+150000, 230+150000, 0, 0, Text))
 {
   CoordMode, Mouse
   X:=ok.1.x, Y:=ok.1.y, Comment:=ok.1.id
   ; Click, %X%, %Y%
 }

 MsgBox, 4096, Tip, % "Found :`t" Round(ok.MaxIndex())
   . "`n`nTime  :`t" (A_TickCount-t1) " ms"
   . "`n`nPos   :`t" X ", " Y
   . "`n`nResult:`t" (ok ? "Success !" : "Failed !")

 for i,v in ok
   if (i<=2)
     FindText_MouseTip(ok[i].x, ok[i].y)
 
		 
		 
		 
	SendInput +{tab}
	Sleep 200
	SendRaw intitle:
return
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

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

21 May 2020, 15:18

@reverberation, your code (with my text capture substituted, of course) is working fine for me. You may just have to uncomment this line

Code: Select all

   ; Click, %X%, %Y%
to

Code: Select all

   Click, %X%, %Y%
. My working code (which won't work on your system, probably), is this:

Code: Select all

; Run Title Search Evernote using Ctrl+Win+3
#Include FindText.ahk
^#3::
IfWinExist ahk_class ENMainFrame
	WinActivate
else
	Run C:\Program Files (x86)\Evernote\Evernote.exe
	Sleep 1000
	SendInput {f9}
	SendInput ^!f
	Sleep 100
	SendInput {tab}{home} ;scroll to top of notes
	Sleep 50

		 
 t1:=A_TickCount, X:=Y:=""

Text:="|<ReminderButton>*197$24.00003k3k7bts6DwM6QCM6s7M1k3U1U9U1UFU1XVU1V1U1k3U0s700wD00zz01btU1U1U0000U"

 if (ok:=FindText(1740-150000, 158-150000, 1740+150000, 158+150000, 0, 0, Text))
 {
   CoordMode, Mouse
   X:=ok.1.x, Y:=ok.1.y, Comment:=ok.1.id
   Click, %X%, %Y%
 }

 ;~ MsgBox, 4096, Tip, % "Found :`t" Round(ok.MaxIndex())
   ;~ . "`n`nTime  :`t" (A_TickCount-t1) " ms"
   ;~ . "`n`nPos   :`t" X ", " Y
   ;~ . "`n`nResult:`t" (ok ? "Success !" : "Failed !")

 for i,v in ok
   if (i<=2)
     FindText_MouseTip(ok[i].x, ok[i].y)
 
		 
		 
		 
	SendInput +{tab}
	Sleep 200
	;SendRaw intitle:
return
Regards,
burque505

Edit: I also commented out the MsbBox command and the

Code: Select all

SendRaw intitle:
for debugging.
reluct
Posts: 134
Joined: 28 Nov 2018, 05:07

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

21 May 2020, 17:23

Hi. After the script found the text, how to click on it?
Something like this:

Code: Select all

{
ImageSearch, X, Y, 0, 0, A_ScreenWidth, A_ScreenHeight, otter.png
If (!ErrorLevel)
{
MouseClick, Left, %ImageX%, %ImageY% ; Clicks the UPPER RIGHT corner of the found image
			Send z
}
User avatar
boiler
Posts: 16705
Joined: 21 Dec 2014, 02:44

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

21 May 2020, 17:53

reluct wrote:
21 May 2020, 17:23
Hi. After the script found the text, how to click on it?
Something like this:

Code: Select all

{
ImageSearch, X, Y, 0, 0, A_ScreenWidth, A_ScreenHeight, otter.png
If (!ErrorLevel)
{
MouseClick, Left, %ImageX%, %ImageY% ; Clicks the UPPER RIGHT corner of the found image
			Send z
}
The script above does not use FindText. If you just want to know how to make the above work, one problem is that you found the image at coordinates X, Y, but then you click on ImageX, ImageY. Change ImageX and ImageY to X and Y. If that's all you're looking to do, you should post in a new thread instead of in this one.
reluct
Posts: 134
Joined: 28 Nov 2018, 05:07

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

21 May 2020, 18:24

boiler wrote:
21 May 2020, 17:53
The script above does not use FindText. If you just want to know how to make the above work, one problem is that you found the image at coordinates X, Y, but then you click on ImageX, ImageY. Change ImageX and ImageY to X and Y. If that's all you're looking to do, you should post in a new thread instead of in this one.
I want to do the same using FindText.
User avatar
boiler
Posts: 16705
Joined: 21 Dec 2014, 02:44

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

21 May 2020, 18:51

reluct wrote:
21 May 2020, 18:24
I want to do the same using FindText.
From the comments at the beginning of the FindText script:
FindText wrote:; Introduction of function parameters:
;
; returnArray := FindText(
; X1 --> the search scope's upper left corner X coordinates
; , Y1 --> the search scope's upper left corner Y coordinates
; , X2 --> the search scope's lower right corner X coordinates
; , Y2 --> the search scope's lower right corner Y coordinates
; , err1 --> Fault tolerance percentage of text (0.1=10%)
; , err0 --> Fault tolerance percentage of background (0.1=10%)
; , Text --> can be a lot of text parsed into images, separated by "|"
; , ScreenShot --> if the value is 0, the last screenshot will be used
; , FindAll --> if the value is 0, Just find one result and return
; , JoinText --> if the value is 1, Join all Text for combination lookup
; , offsetX --> Set the max text offset for combination lookup
; , offsetY --> Set the max text offset for combination lookup
; )
;
; The function returns a second-order array containing
; all lookup results, Any result is an associative array
; {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.
;
; If the return variable is set to "ok", ok.1 is the first result found.
; Where ok.1.1 is the X coordinate of the upper left corner of the found image,
; and 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, and 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 ),
; ok.1.id is the comment text, which is included in the <> of its parameter.
; ok.1.x can also be written as ok[1].x, which supports variables. (eg: ok[A_Index].x)
;
; All coordinates are relative to Screen, colors are in RGB format,
; and combination lookup must use uniform color mode
So if you assign the results to a variable named Image, the center of the first found image is in Image.1.x, Image.1.y, so you would do this:

Code: Select all

MouseClick, Left, Image.1.x, Image.1.y
and your if statement would be (assuming you've already assigned the result of the function to Image):

Code: Select all

if Image
reluct
Posts: 134
Joined: 28 Nov 2018, 05:07

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

22 May 2020, 02:41

@boiler
Thx, I just could not recognize what it is X:=ok.1.x, Y:=ok.1.y
User avatar
SirSocks
Posts: 360
Joined: 26 Oct 2018, 08:14

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

27 May 2020, 13:31

Can FindText click on images that are different scales? I would like my script to click on "Image 1" and "image 2".
Sometimes the scale of the item I want to click will differ. How can scale be compensated for?

Image
paulpma
Posts: 65
Joined: 08 Sep 2018, 22:05

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

02 Jun 2020, 01:16

To my knowledge the way findtext works you would have to capture the image at each scale size that you want it to be found and then use capture strings as a library for findtext.. I hope it helps to understand..
andy5566888
Posts: 10
Joined: 07 May 2020, 02:20

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

08 Jun 2020, 02:39

@paulpma i want to ask you some question about your bindwindow question is already solve? because i encounter the same question

[BindWindow and BindWindow+ feature, but to my knowledge they can be used only if window still open?]
someone can help me?
iwrk4dedpr
Posts: 16
Joined: 18 Aug 2014, 23:01

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

08 Jun 2020, 18:19

I am trying to find all the "3's" at the moment in the below picture. I have 1000's of other pictures of other sudoku game solutions.

I'm using this FindText.ahk because I was trying to figure this out before I did the upgrade to FindText and OCR method. So on to my ???'s

1. In my attempts ... when I don't appear to find all of the 3's in an image I then "LEARN" that image and add it's code to my "TEXT". Hence the multiple items below. I've tried to use the "ERR" parameters but I can't seem to get them to work. ( trying to reduce the number of TEXT's below ) also when I chg the image to get it to work on a new picture.

2. Also, when I watch it will "highlight" the same number more than once sometimes. Is there a "UNIQUE" setting?

Code: Select all

	Text:="|<3>**50$16.1w0Tw3zsS1lk3a0CE0s03U0Q03k7w0Tk1zk07U0C00Q01w07s0Nk3bUQDzUDw8"
	Text.="|<3>**50$16.0M0Dw3zsS3lk760CM0s03U0A01k0y0Tk1zU0700C00M01w07s0PU3bUSDzkTw0D0U"
	Text.="|<3>*150$18.0001zU3zk70sC0MA0QA0Q00Q00M00s03k0zU0Tk00s00A00C00CM0CQ0AA0QD0s7zs1zU000U"
	Text.="|<3>*150$16.0s0Tw3zsQ1lk360CE0s0300A01U7w0Tk0zU0700C00M01w07s0NU3bUQDzUDw8"
	Text.="|<3>*150$16.000Ds1lsA1lU360A00k0300A01U0A0TU07U0300600M01Y06E0NU1b0QDbUDs000U"
	Text.="|<3>*150$17.0003y0Tz1k730660A80M00k01U0600s0TU0zk01k01k01U03A06Q0AM0ss3Uzy0zs000U"
	Text.="|<3>*150$17.0003y0Tz1k730660A80M00k01U0600s0TU0zk01k01k01U03A06Q0AM0ss3Uzy0zs000U"
	Text.="|<3>*150$16.0M0Dw3vsC1lk360CE0s03U0A01k3w0Tk0Dk03U0600Q01w07s0Nk3XUQDzUDw8"
	Text.="|<3>*150$14.7w3XlUAk1g0M0601U0M0A060z00w01U0A0300s0C03k0y0tsw7w8"




IMG_0261.PNG
IMG_0261.PNG (162.17 KiB) Viewed 3274 times
saph
Posts: 68
Joined: 25 May 2020, 12:09

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

09 Jun 2020, 08:59

Hello,

First off the script is amazing. This has made my life so much easier, is there a donation place or something I can send something too? It's really helped. Thank you!

Looking for some help with the below. I'm trying to loop the "if" statement below until the "else" actives and then I'd like the code to stop.

I've used MsgBox % result to see what's happening and I only ever get a blank or a 0, never a one and I don't know where to go from here! Can anyone help?

Code: Select all

CoordMode, Mouse, Screen
t1 := A_TickCount, X := Y := ""

	Text:="|<Lv.12>**50$54.w0000Trzsy0000Trzsa0000EI08a0TDUEI0Da0HAUSLzna0HAU6Ezna0HAU6Fzna0HAU6FU3a0HAU6LU3a0HAU6IzzbzHwj6IzybzTzjaIzzU1S7daI03U1669aI03zz7yDzrzzU"
	
result := FindText(-804-150000, 79-150000, -804+150000, 79+150000, 0, 0, Text)
Loop
{
	Msgbox % result
	if (result) {            	    ;if "results" = 0, click "keep looking". 0 means "found the level 12 text"
			Click, -173, 980 		;keep looking
 	} else {				 		;if "results" = anything else, click "attack". 
		    Click, -485, 989 		;attack
           }
}
Until result = 1
Last edited by saph on 10 Jun 2020, 21:12, edited 1 time in total.
R0nya
Posts: 6
Joined: 05 Aug 2016, 09:30

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

10 Jun 2020, 10:00

The bug?
When I use BindWindow the function uses coordinates not of that window but the whole screen so if I move that window the script won't find anything. I guess it's supposed to use coordinates only on the selected window.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: JoeWinograd and 70 guests