FindText - Capture screen image into text and then find it

Post your working scripts, libraries and tools
MasterDiver69
Posts: 1
Joined: 01 Jan 2020, 15:07

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

19 Jan 2020, 12:41

Hi feiyue, thanks for this! I apologize for this simple question. I've spent hours and cannot seem to figure it out. How do I use a portion of your function to determine whether a text string is on the screen? I just need to simply determine if the text "Enter" is shown anywhere on screen. If (FindText(...) = yes), then enter some text in a field on the screen; else return. Thanks for help on this!
ahk nooblie
Posts: 6
Joined: 19 Jan 2020, 00:49

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

19 Jan 2020, 13:20

feiyue wrote:
19 Jan 2020, 05:40
@ahk nooblie I think you can do this:

Code: Select all

#MaxThreadsPerHotKey 3
#NoEnv
SetDefaultMouseSpeed, 0


F2::
Toggle := !Toggle
Loop
{

	Text1:="|<>*160$58.D6k20A0001WP080k000ABU0U30000U6lmMDVltm0P9f0n8a8c1hUs34WMWU6q3UAHxXz3PM90l86869gWa34WMWD6lm8AFtVu"
	if (ok:=FindText(818,625,973,730, 0, 0, Text1))
	CoordMode, Mouse
	X:=ok.1.1, Y:=ok.1.2, w:=ok.1.3, h:=ok.1.4
	Random, i, 0, w
	Random, j, 0, h
	Click, % X+i, % Y+j

	Text2:="|<>*182$59.Tzzzzzzzzx0000000006000000000A000000000M000000000k3y0000001U6A00400k30AA00801U60MMswtszUA0lX9AWNa0M1y4P10mA0k3ATnmDYM1U6AE1Yn8k30A8nl9aFU60MMwwRwVUA000000000M000000000k000000001U0000000030000000005zzzzzzzzzo"

	if (ok:=FindText(810,548,958,607, 0, 0, Text2))
	CoordMode, Mouse
	X:=ok.1.1, Y:=ok.1.2, w:=ok.1.3, h:=ok.1.4
	Random, i, 0, w
	Random, j, 0, h
	Click, % X+i, % Y+j
	
	If (!Toggle)
		Break
}
Return
I tried something similar to that and this one gave me the same error :headwall:
Attachments
Annotation 2020-01-19 131654.png
Annotation 2020-01-19 131654.png (17.22 KiB) Viewed 976 times
feiyue
Posts: 200
Joined: 08 Aug 2014, 04:08

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

19 Jan 2020, 21:37

Correct it:

Code: Select all

#MaxThreadsPerHotKey 3
#NoEnv
SetDefaultMouseSpeed, 0
#Include <FindText>

F2::
Toggle := !Toggle
Loop
{

	Text1:="|<>*160$58.D6k20A0001WP080k000ABU0U30000U6lmMDVltm0P9f0n8a8c1hUs34WMWU6q3UAHxXz3PM90l86869gWa34WMWD6lm8AFtVu"
	if (ok:=FindText(818,625,973,730, 0, 0, Text1))
	CoordMode, Mouse
	X:=ok.1.1, Y:=ok.1.2, w:=ok.1.3, h:=ok.1.4
	Random, i, 0, w-1
	Random, j, 0, h-1
	MouseClick,, X+i, Y+j

	Text2:="|<>*182$59.Tzzzzzzzzx0000000006000000000A000000000M000000000k3y0000001U6A00400k30AA00801U60MMswtszUA0lX9AWNa0M1y4P10mA0k3ATnmDYM1U6AE1Yn8k30A8nl9aFU60MMwwRwVUA000000000M000000000k000000001U0000000030000000005zzzzzzzzzo"

	if (ok:=FindText(810,548,958,607, 0, 0, Text2))
	CoordMode, Mouse
	X:=ok.1.1, Y:=ok.1.2, w:=ok.1.3, h:=ok.1.4
	Random, i, 0, w-1
	Random, j, 0, h-1
	MouseClick,, X+i, Y+j
	
	If (!Toggle)
		Break
}
Return
ahk nooblie
Posts: 6
Joined: 19 Jan 2020, 00:49

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

22 Jan 2020, 21:02

feiyue wrote:
19 Jan 2020, 21:37
Correct it:

Code: Select all

#MaxThreadsPerHotKey 3
#NoEnv
SetDefaultMouseSpeed, 0
#Include <FindText>

F2::
Toggle := !Toggle
Loop
{

	Text1:="|<>*160$58.D6k20A0001WP080k000ABU0U30000U6lmMDVltm0P9f0n8a8c1hUs34WMWU6q3UAHxXz3PM90l86869gWa34WMWD6lm8AFtVu"
	if (ok:=FindText(818,625,973,730, 0, 0, Text1))
	CoordMode, Mouse
	X:=ok.1.1, Y:=ok.1.2, w:=ok.1.3, h:=ok.1.4
	Random, i, 0, w-1
	Random, j, 0, h-1
	MouseClick,, X+i, Y+j

	Text2:="|<>*182$59.Tzzzzzzzzx0000000006000000000A000000000M000000000k3y0000001U6A00400k30AA00801U60MMswtszUA0lX9AWNa0M1y4P10mA0k3ATnmDYM1U6AE1Yn8k30A8nl9aFU60MMwwRwVUA000000000M000000000k000000001U0000000030000000005zzzzzzzzzo"

	if (ok:=FindText(810,548,958,607, 0, 0, Text2))
	CoordMode, Mouse
	X:=ok.1.1, Y:=ok.1.2, w:=ok.1.3, h:=ok.1.4
	Random, i, 0, w-1
	Random, j, 0, h-1
	MouseClick,, X+i, Y+j
	
	If (!Toggle)
		Break
}
Return
Xiexie my friend. :beer:
rezaebrahimyan
Posts: 2
Joined: 24 Jan 2020, 03:15

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

24 Jan 2020, 06:03

hello
im new here and just started using ahk and learning its language
can anyone please learn me how to use this script?
i puted the script in a ahk file and added this code :
F2::
FindText( 0, 0, 1000, 1000, 0.1, 0.1, text, ScreenShot:=1
, FindAll:=1, JoinText:=0, offsetX:=20, offsetY:=10 )
return

where should i copy my text to search
how should i know what happend?
my need = i need to detect the error's in a registration page like this :
Аккаунт с таким именем уже существует
and its in red color
thanks
thebbandit
Posts: 26
Joined: 02 Jul 2019, 11:34

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

27 Jan 2020, 22:52

This weekend I spent some time learning how to use classes in AHK, and I have come up with a tool designed for FindText that I thought I should share.
PanelManager
Insert and test
leosouza85
Posts: 37
Joined: 22 Jul 2016, 16:28

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

03 Feb 2020, 11:19

I want to perform a findtext and do a msgbox with the total number of results found.

Example I have 100 items on my screen. I know how to use findtext to find the first item. I only need help to msgbox the total of itens found on the screen, could someone help? (My english is bad)
leosouza85
Posts: 37
Joined: 22 Jul 2016, 16:28

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

03 Feb 2020, 14:13

feiyue wrote:
03 Feb 2020, 14:03
MsgBox, % ok.MaxIndex()
Thank you!
The answer is always 1024, this is the limit?
leosouza85
Posts: 37
Joined: 22 Jul 2016, 16:28

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

03 Feb 2020, 16:19

leosouza85 wrote:
03 Feb 2020, 14:13
feiyue wrote:
03 Feb 2020, 14:03
MsgBox, % ok.MaxIndex()
Thank you!
The answer is always 1024, this is the limit?
Found the issue! changed the maximum number to 1.000.000 in findtext source instead of 1024. 1024 is low when counting individual pixels total.
OMGmarc
Posts: 1
Joined: 05 Feb 2020, 23:46

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

06 Feb 2020, 00:17

Hello. I first want to thank the author and other contributors to this thread. Thanks to you, I've been able to create one heck of a robust (compared to my original ImageSearch version) AHK script.
Last edited by OMGmarc on 06 Feb 2020, 20:41, edited 1 time in total.
Bearvius
Posts: 2
Joined: 06 Feb 2020, 14:45

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

06 Feb 2020, 15:04

Hello, thanks for a great script! However I am facing issues when using the "console" to capture the pattern on one particular PC all of a sudden.

I was able to open the script and capture the pattern of interest and then incorporate the code in my own script. But suddenly it stopped working on one particular machine without any apparent reason. This PC has been running as a headless system entirely disconnected from Internet and other user interference for the last few months. It was working entirely fine before this. It is a win 10 machine.

What happens now is that when I open the FindText script to capture the pattern, the system doesn't react to right clicks and I am unable to capture the pattern or do anything with the right click. The only way to close the script is to use the task manager.

I also seem to be unable to use Click commands in scripts so might be an underlying issue at work.. Anyways, your feedback would be most appreciated.
Bearvius
Posts: 2
Joined: 06 Feb 2020, 14:45

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

07 Feb 2020, 07:42

Just a small update from me: although I couldn't get right click to work, I was able to use Ctrl button to capture the pattern instead. Still trying to figure out why it stopped working, though...
thebbandit
Posts: 26
Joined: 02 Jul 2019, 11:34

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

08 Feb 2020, 17:57

@Bearvius
Inside the GUI function, you can add a line to reset the hotkey "conditions" maybe you have changed them?

inside the capture section you can put this line near the top, and it may fix your issue. Maybe you have put other conditional hotkeys into your script and it is affecting this library. I had a similar issue myself when trying to use this library as part of a larger script. it should look like this

Code: Select all

    ;------------------------------
	Hotkey, IfWinActive
  	Hotkey, $*RButton, ft_RButton_Off, On
the section your looking for in the code starts with

Code: Select all

  if (cmd="Capture") or (cmd="CaptureS")
User avatar
Chunjee
Posts: 321
Joined: 18 Apr 2014, 19:05
GitHub: Chunjee

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

09 Feb 2020, 12:42

I started experimenting with this group of functions and really like it. I wish it was a class so as not to add so many functions to the global scope but I'll worry about fixing that later.

I have a question that I wasn't able to answer from the docs. Many searches end up looking like:
0000000000000000000______0
00000000000000000000______
000000000000000000000000__
000000000000000000000000__
00000000000000000000000___

  1. is there a way to wildcard some or part of the graphic?
  2. Is there somewhere I can read more about GrayDiff, Color, ColorPos, ColorDiff?
peameedo112
Posts: 1
Joined: 12 Feb 2020, 19:14

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

12 Feb 2020, 19:35

Hello,
Does it possible to find text from hBitmap directly?

thanks!

Return to “Scripts and Functions”

Who is online

Users browsing this forum: AHK_user, Google [Bot], KentC and 75 guests