FindText tutorial

Helpful script writing tricks and HowTo's
Descolada
Posts: 1431
Joined: 23 Dec 2021, 02:30

Re: FindText tutorial

05 Jul 2022, 00:20

@Mrcbst, my best bet is that when the image appears elsewhere, it looks slightly different on a pixel level (for example antialiasing causes this in many programs and browsers). To test this theory out: capture a screenshot of the working image that can be found, and a screenshot of the non-working image. Then set search scope to the whole screen and check if both can be found.

Other possible causes: your search scope might be too small and the image appears outside of it. You can check that by drawing out the search range with FindText().RangeTip.
Of course there is a very slight chance of a bug in FindText, but since MultiColor search has worked so far without any bug reports it's unlikely...

Note: providing a test image to try your Text out with would also be of great help in debugging.
Mrcbst
Posts: 5
Joined: 04 Jul 2022, 20:55

Re: FindText tutorial

06 Jul 2022, 00:58

Descolada wrote:
05 Jul 2022, 00:20
@Mrcbst, my best bet is that when the image appears elsewhere, it looks slightly different on a pixel level (for example antialiasing causes this in many programs and browsers). To test this theory out: capture a screenshot of the working image that can be found, and a screenshot of the non-working image. Then set search scope to the whole screen and check if both can be found.

Other possible causes: your search scope might be too small and the image appears outside of it. You can check that by drawing out the search range with FindText().RangeTip.
Of course there is a very slight chance of a bug in FindText, but since MultiColor search has worked so far without any bug reports it's unlikely...

Note: providing a test image to try your Text out with would also be of great help in debugging.
Yea, that was it. Basically the image was slightly varying in each possible slot. Some images worked because the colors were so similar that setting a basic threshold seemed to capture it anyways, but images with strongly contrasting colors need to be searched for, for each slot individually, basically I was searching for 2 images, one was basically a brownish/orange, the other was white and purple, the brownish orange one worked wherever it popped up, the white/purple one requires me to append each possible image for each slot.

It's working now though, so thanks :) Oh, it wasn't anti-aliasing in this case, I turned it all off and it made no difference.
tbycidiot
Posts: 1
Joined: 15 Jul 2022, 19:43

Re: FindText tutorial

15 Jul 2022, 19:45

When I follow the getting started section and run the first test program I get the error:
Error at line 1879 in #include file "C:\Users\Me\Documents\AutoHotkey\Lib\FindText.ahk".

Line Text: Switch cmd
Error: This line does not contain a recognized action.

Any idea what I could do to fix this or what I've done wrong? Thank you!
User avatar
gregster
Posts: 9224
Joined: 30 Sep 2013, 06:48

Re: FindText tutorial

15 Jul 2022, 19:51

tbycidiot wrote:
15 Jul 2022, 19:45
Line Text: Switch cmd
Error: This line does not contain a recognized action.

Any idea what I could do to fix this or what I've done wrong? Thank you!
Update your AHK version. Switch was introduced in v1.1.31.
guest3456
Posts: 3477
Joined: 09 Oct 2013, 10:31

Re: FindText tutorial

21 Jul 2022, 09:03

excellent tutorial

Mrcbst
Posts: 5
Joined: 04 Jul 2022, 20:55

Re: FindText tutorial

26 Jul 2022, 18:34

I've got another question regarding efficiency. How would this method compare in terms of efficiency/speed to pixel search, if you're searching a single pixel. Would it be noticeably faster? Not noticeably faster? For clarity, it would be searching somewhere between say 18 and 24 or so individual 1x1 locations.
Descolada
Posts: 1431
Joined: 23 Dec 2021, 02:30

Re: FindText tutorial

27 Jul 2022, 08:04

@Mrcbst, I haven't done any speed tests for that, since there are better options available for single pixel search. My guess is that it will be slower than PixelSearch with the Fast option if you take a new screenshot every time, but faster than PixelSearch if you search your 18-24 pixels on the same screenshot. If you decide to run the tests on that, be sure to share the results here :)
Also perhaps take a look at this thread and this library, they use similar methods as FindText does.
Mrcbst
Posts: 5
Joined: 04 Jul 2022, 20:55

Re: FindText tutorial

30 Jul 2022, 19:04

Those look interesting, thanks. I've got another question. When using the multicolor search with the findmulticolor box ticked, and you are adding colors via clicking on each pixel. What happens/how does the script handle pixels you don't click to add that color to the search? Are those pixels left out of the search?
Descolada
Posts: 1431
Joined: 23 Dec 2021, 02:30

Re: FindText tutorial

30 Jul 2022, 22:59

@Mrcbst, yes, the pixels that were not selected should be ignored by FindText. That is to say that the script will look for a place on the screen that has your selected pixel colors at the same relative locations to each other.
So if you select two pixels right next to each other, then this would be similar to looking for the first pixel with PixelSearch, and then checking if the pixel next to that one matches as well; if not, then the next pixel will be searched that matches the first pixel color and so on.
Mrcbst
Posts: 5
Joined: 04 Jul 2022, 20:55

Re: FindText tutorial

31 Jul 2022, 21:21

Alright, thanks for the info :)
John1
Posts: 236
Joined: 11 May 2020, 11:54

Re: FindText tutorial

10 Aug 2022, 14:25

Hello,

Thank you for your very helpful tutorial!

How can i look at the current mouse position. Take there a small screenshot and stop click when the screenshot changes/ when the screen changes at that position?

Thank you!

Code: Select all

1::
MouseGetPos, StartX1, StartY1
FindText().ScreenShot(StartX1-20,StartY1-20,StartX1+20,StartY1+20)
return

2::
MouseGetPos, StartX1, StartY1
Loop,20 {
Text:="|<(IMAGE 1)>*20gfgfrdfd9534jdfd74313"
if (ok := FindText(X,Y,StartX1-20,StartY1-20,StartX1+20,StartY1+20,0.000001,0.000001, Text))
{
	break
}

else
{
    Click
}
} ;Loop Ende
}
return
Descolada
Posts: 1431
Joined: 23 Dec 2021, 02:30

Re: FindText tutorial

10 Aug 2022, 23:21

@John1, what you want might be possible with FindText, but it isn't built for that... I would recommend using another function such as ScrCmp by SKAN, much easier.
John1
Posts: 236
Joined: 11 May 2020, 11:54

Re: FindText tutorial

11 Aug 2022, 03:03

@Descolada Thank you a lot for your reply!
John1
Posts: 236
Joined: 11 May 2020, 11:54

Re: FindText tutorial

20 Aug 2022, 13:09

@Descolada

Hello,

i have another question.

At 8) FindText combination lookup. it says
where "key" can be a maximum of 20 pixels away from "auto" in the x-axis and 10 pixels away
My question is: is it possible to change the maximum of pixels in x-axis it can be away for example something to 1-5 pixels?
Text:="|<auto>*159$40.0000k000003000000A00DVUnw7lr6371nUAMAA630FUkkkAT63330rgMAAA1kFUkkkD363330wAAAA62vkvkkQtt1v1kS8"
Text.="|<hot>*152$29.U00010000200014000280004Hk7kzxktktVVUkX161V43A3286M24EAkA8UNUMF0lUUW1Xb1g31s1s"
MsgBox, Looking for "auto" and "hot"
ok:=FindText(X,Y,,,,,,,Text) ; FindText will return all locations of both "auto" and "key" separately
for k, v in ok
FindText().MouseTip(v.x, v.y)
MsgBox, Looking for "auto" followed by "hot"
ok:=FindText(X,Y,,,,,,,Text,,,1) ; FindText will return all locations of "auto" followed by "key", where "key" can be a maximum of 20 pixels away from "auto" in the x-axis and 10 pixels away in the y-axis
for k, v in ok
FindText().MouseTip(v.x, v.y)
Thank you!
Have a good day.
Descolada
Posts: 1431
Joined: 23 Dec 2021, 02:30

Re: FindText tutorial

20 Aug 2022, 13:24

@John1, yes, these can be changed by supplying the offsetX and offsetY arguments of the FindText function. By default (if not supplied) they are 20 and 10.
John1
Posts: 236
Joined: 11 May 2020, 11:54

Re: FindText tutorial

21 Aug 2022, 03:53

@Descolada

Thank you for your reply!

Version 1: works fine

Code: Select all

if (ok := FindText(X,Y,0,0,0,0,0.000001,0.000001, Text,,0,["WORD 1 WORD 2"]))
{
    MouseMove, X, Y, 0
}
Version 2: works not. did i wrote it correct?

Code: Select all

if (ok := FindText(X,Y,0,0,0,0,0.000001,0.000001, Text,,0,,,,20,10,["WORD 1 WORD 2"]))
{
    MouseMove, X, Y, 0
}
already when i just add one comma it works not.

Code: Select all

if (ok := FindText(X,Y,0,0,0,0,0.000001,0.000001, Text,,0,,["WORD 1 WORD 2"]))
{
    MouseMove, X, Y, 0
}
Descolada
Posts: 1431
Joined: 23 Dec 2021, 02:30

Re: FindText tutorial

21 Aug 2022, 07:15

FindText has the following arguments: FindText(OutputX, OutputY, X1, Y1, X2, Y2, err1, err0, Text, ScreenShot, FindAll, JoinText, offsetX, offsetY, dir)

Version 1: FindText(X,Y,0,0,0,0,0.000001,0.000001, Text,,0,["WORD 1 WORD 2"]) you have set FindAll to 0 and JoinText to ["WORD 1 WORD 2"] (though you should set FindAll to 1 here, or leave empty)
Version 2: FindText(X,Y,0,0,0,0,0.000001,0.000001, Text,,0,,,,20,10,["WORD 1 WORD 2"]) you have given FindText too many arguments.

Correct: FindText(X,Y,0,0,0,0,0.000001,0.000001, Text,,,["WORD 1 WORD 2"], 20, 10)
John1
Posts: 236
Joined: 11 May 2020, 11:54

Re: FindText tutorial

21 Aug 2022, 13:39

@Descolada
Thanks a lot master!
dox
Posts: 27
Joined: 03 Apr 2017, 12:23

Scaling clarification

31 Aug 2022, 01:14

Many thanks to OP (Descolada) for the excellent tutorials and to Feiyue for making this possible!

Just a clarification so that others don't get stumped like I did initially. OP had written that for the purposes of these tutorials, Windows DPI scaling should be set at "100%".

However, at 100% the Notepad OCR example (#9) simply doesn't work. It only works (like a charm in fact) at a "custom scaling" factor of 150% (under Advanced scaling settings). We all know Windows 10's DPI scaling options are still a bit messy, to say the least - in fact quite suboptimal for me, a Citrix sufferer.

Hope to double-check on the scaling so as to avoid anything inadvertently "misleading".

BTW, this package seems to be missing Citrix "slayer" I wish I had known years ago.

Warm regards and many thanks!
Descolada
Posts: 1431
Joined: 23 Dec 2021, 02:30

Re: FindText tutorial

31 Aug 2022, 09:05

@dox, thanks, fixed! The correct DPI is 150%.

Return to “Tutorials (v1)”

Who is online

Users browsing this forum: No registered users and 42 guests