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 3414 times
feiyue
Posts: 226
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: 27
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: 41
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: 41
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: 41
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: 4
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: 27
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: 602
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!
User avatar
tobsto occupied
Posts: 74
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

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

20 Feb 2020, 09:41

ok , got a real problem as of lately over here thats been bugging the hell out of my noob mind, ive been tinkering with a script to autolaunch my games that use game launchers , which have buttons like > Play< or > Launch Game<

this is what ive gotten to work with from chunjee>

Code: Select all

#NoTrayIcon
#SingleInstance, force
SetBatchLines, -1

#Include node_modules
#Include graphicsearch.ahk\export.ahk
oGraphicSearch := new graphicsearch()

; ~~~ variables ~~~
; searchable graphics
launchGraphic := "|<launch>**25$63.k0DyD1lzs7y01ztwSDzUzk0zzDXlzyTy07XtwSDbnnk0wTDXlwyyS00TtwSD7rUk03zDXlsyw607ztwSD7bUk0zzDXlsyw607ttwSD7rUk1sDDXlsyw60D3twSD7nns3wzjblsyTzzrzwzyD7nzzyzrXzlsS7zznysDyC1UzU"

#p::
CoordMode, Mouse, Screen
result := oGraphicSearch.search(0, 0, A_ScreenWidth, A_ScreenHeight, 0, 0, launchGraphic)
if (result) {
    ; click all found images
    for i, obj in result {
        Click, obj.x, obj.y
        sleep, 300
    }
}
return
and this is how ive modified it , both dont do shit>

Code: Select all

#SingleInstance, force
SetBatchLines, -1

#Include node_modules
#Include graphicsearch.ahk\export.ahk
oGraphicSearch := new graphicsearch()

; ~ variables ~
; searchable graphics
launchGraphic := "|<Play>**25$63.k0DyD1lzs7y01ztwSDzUzk0zzDXlzyTy07XtwSDbnnk0wTDXlwyyS00TtwSD7rUk03zDXlsyw607ztwSD7bUk0zzDXlsyw607ttwSD7rUk1sDDXlsyw60D3twSD7nns3wzjblsyTzzrzwzyD7nzzyzrXzlsS7zznysDyC1UzU"

#p::
CoordMode, Mouse, Screen
result := oGraphicSearch.search(1655, 530, A_ScreenWidth, A_ScreenHeight, 881, 357, launchGraphic)
if (result) {
    ; click all found images
    for i, obj in result {
        Click, 428, 45
        sleep, 300
    }
}
return
these are my coords>
x>1655 z>881 w>530 h>357 for active window
and these are for the mouse position aka pointed on the play button> x>428 y>45 w>89 h>29
thebbandit
Posts: 27
Joined: 02 Jul 2019, 11:34

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

20 Feb 2020, 15:15

tobsto occupied wrote:
20 Feb 2020, 09:41
ok , got a real problem as of lately over here thats been bugging the hell out of my noob mind, ive been tinkering with a script to autolaunch my games that use game launchers , which have buttons like > Play< or > Launch Game<

this is what ive gotten to work with from chunjee>

these are my coords>
x>1655 z>881 w>530 h>357 for active window
and these are for the mouse position aka pointed on the play button> x>428 y>45 w>89 h>29
You are using some kind of fork of the findtext library. That looks pretty interesting actually :D share where you got that class based version of this lib

Edit: Did a little digging since I was interested. the Page was here
They did a pretty damn good job converting all of these functions into one class. I can use this to break up the search areas into different instances of the class


OK so to answer your question, It looks as though you are using the syntax of the class incorrectly. Once you have created the class object, you can use oGraphicSearch.Find("Standard Findtext parameters go here") which would replace the oGraphicSearch.search() you have. It looks like .search is actually added to this class specially, and it is a way for the script to use an object for its settings instead of a string of options as the input.

So you would create an object with the same structure as :

Code: Select all

    static optionsObj := {    "x1": 0
                            , "y1": 0
                            , "x2": A_ScreenWidth
                            , "y2": A_ScreenHeight
                            , "err0": 0
                            , "err1": 0
                            , "screenshot": 1
                            , "findall": 1
                            , "joinstring": 1
                            , "offsetx": 1
                            , "offsety": 1 }
Then pass the object into the class's search function like oGraphicSearch.search(ImageString,SettingsObj)

It looks like he designed it so that you can omit the object completely to do a default search, or only include portions of the object to use default for the rest of the settings.
User avatar
tobsto occupied
Posts: 74
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

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

22 Feb 2020, 11:44

well , im sorry , but i dont understand diddly , what am i supposed to do in order for it to work , how and what do i do with my coordinates and change what for it to search for different text or maybe even both , that way i just have to change coordinates but it searches for both ^Play^ and ^Launch Game^, sorry for being such a noob :(
User avatar
Chunjee
Posts: 602
Joined: 18 Apr 2014, 19:05
GitHub: Chunjee

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

22 Feb 2020, 12:28

thebbandit wrote:
20 Feb 2020, 15:15
It looks like he designed it so that you can omit the object completely to do a default search, or only include portions of the object to use default for the rest of the settings.
Yes this is true. I will post more about the fork in the coming week once I can finalize and test things.
thebbandit wrote:
20 Feb 2020, 15:15
I can use this to break up the search areas into different instances of the class
This is one benefit, yup.


For anyone curious, please keep an eye on https://chunjee.github.io/graphicsearch.ahk for documentation and features.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: jeongrak2 and 32 guests