FindText - Capture screen image into text and then find it

Post your working scripts, libraries and tools for AHK v1.1 and older
feiyue
Posts: 349
Joined: 08 Aug 2014, 04:08

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

19 Mar 2021, 04:29

Hagork wrote:
18 Mar 2021, 22:46
I have the script loaded into my script and working. But I can not figure out how to replace the msgbox with a stop/go result.
With imagesearch (which wasn't detecting my image) I used.

Code: Select all

ImageSearch, Px, Py, 219,105, 288, 388, test.bmp
	If Errorlevel
		sleep, 200 ;pic not found, to continue my loop
	Else
		Pause ;pic found, to pause my loop to look at screen, then hotkey to resume the loop
Can FindText be setup for the same output?
Only need a little modification:

Code: Select all

FindText.ImageSearch(Px, Py, 219,105, 288, 388, Text)
	If Errorlevel
		sleep, 200 ;pic not found, to continue my loop
	Else
		Pause ;pic found, to pause my loop to look at screen, then hotkey to resume the loop
Superblyad
Posts: 2
Joined: 19 Mar 2021, 13:30

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

19 Mar 2021, 13:39

how do I use ScreenToWindow() :(
it keeps saying nonexistent function
feiyue
Posts: 349
Joined: 08 Aug 2014, 04:08

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

20 Mar 2021, 16:15

@Superblyad
Functions are included in FindText class, so it should be: FindText.ScreenToWindow(x, y, 111, 222)
Or: aa:=new FindText, aa.ScreenToWindow(x, y, 111, 222)
Last edited by feiyue on 06 Apr 2021, 23:25, edited 1 time in total.
bautai
Posts: 19
Joined: 29 Nov 2020, 02:54

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

25 Mar 2021, 11:35

@feiyue
Does not work. Can you give an example ScreenToClient(),etc.? Thanks

Code: Select all

$b::
Text:="|<>*249$71.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002"
if (ok:=FindText(0-150000, 0-150000, 0+150000, 0+150000, 0, 0, Text)){
	; 1		----------------Result is Blank
	CoordMode, Mouse
	X:=ok.1.1, Y:=ok.1.2
	baba := FindText.ScreenToWindow(x1,y1)
	Msgbox, % x1 " , " y1 "`nvar baba : " baba
	; 2		----------------this Result is Blank too
	; id := WinExist("A")
	; test12 := FindText.ClientToScreen(x1,y1,id)
	; Msgbox, % x1 " , " y1 "`nvar test12 : " test12
}
tuzi
Posts: 223
Joined: 27 Apr 2016, 23:40

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

27 Mar 2021, 23:53

我在 KMCounter 里,直接用这种形式自动加载对应语言文件,这样就不用发布和维护多个版本了,要是 FindText 也用这种方式,应该也可以轻松一些。 :D

Code: Select all

  if (A_Language="0804")
  {
    L_menu_统计:="统计"
  }
  else
  {
    L_menu_统计:="Statistics"
  }
feiyue
Posts: 349
Joined: 08 Aug 2014, 04:08

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

29 Mar 2021, 14:04

@bautai You can use it like this:

Code: Select all

$b::
Text:="|<>*249$71.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002"
if (ok:=FindText(0-150000, 0-150000, 0+150000, 0+150000, 0, 0, Text))
{
	; 1
	FindText.ScreenToWindow(x1, y1, ok.1.x, ok.1.y)
	Msgbox, % x1 " , " y1 "`nvar baba : "
	; 2
	id := WinExist("A")
	FindText.ClientToScreen(x1, y1, ok.1.x, ok.1.y, id)
	Msgbox, % x1 " , " y1 "`nvar test12 : "
}
@tuzi
It's a good way, but I didn't integrate multiple languages in one script
considering that annotations also need to be translated. :beer:
Last edited by feiyue on 06 Apr 2021, 23:26, edited 1 time in total.
tuzi
Posts: 223
Joined: 27 Apr 2016, 23:40

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

30 Mar 2021, 02:00

要不把注释写一起?

Code: Select all

这是一条注释。
this is a comment.
User avatar
tdalon
Posts: 41
Joined: 21 Apr 2017, 07:19
Location: Germany
Contact:

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

31 Mar 2021, 06:25

How to limit search in current window?

Code: Select all

WinGetPos, x,y,w,h,A ; (x,y) upper left corner
X1 := x, Y1 := y, X2 := x+w, Y2 := y-h  ; (X1,Y1): upper left corner, (X2,Y2): lower right corner
If (ok:=FindText(X1,Y1,X2,Y2, 0, 0, Text)) 
does not work.
bautai
Posts: 19
Joined: 29 Nov 2020, 02:54

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

31 Mar 2021, 18:46

@feiyue Aww, thanks for example :dance: :clap:
feiyue
Posts: 349
Joined: 08 Aug 2014, 04:08

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

01 Apr 2021, 16:18

Updated to 8.4 version - 2021/04/02 :dance: :beer:
.... 1. Improvement: in multicolor mode,You can find multiple colors and adapt to different resolutions.
....... Now it also supports searching images, for example: Text:="|<>##10$ c:\a.bmp"
....... It's better to limit the search range to a small one.
.... 2. Modify: the return value of OCR identification function is changed.
....... eg: MsgBox, % FindText.Ocr(ok).ocr --> Change to: MsgBox, % FindText.Ocr(ok).text
.... 3. Add: FindText.QPC() and FindText.SetColor() is added.
.... 4. Modify: The search direction (dir = 1-9), dir = 9: From the Center to all around.
Last edited by feiyue on 06 Apr 2021, 19:22, edited 2 times in total.
chaoscreater
Posts: 59
Joined: 12 Sep 2019, 21:15

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

01 Apr 2021, 22:34

I have 2 PCs with 2 different maximum screen resolutions. PC1 has 1920x1080 and PC2 has 1366x768. PC1 is my primary machine, which I use the most.

Let's say on PC1, I take a screen capture using Findtext and the automatically generated code works fine on PC1. Is there an easy way to make this code work for PC2, considering that it has a lower maximum screen resolution? I don't want to have to do multiple screen captures on 2 different machines (and possibly more). I'd like to just generate a piece of code and have it work across machines.
User avatar
ivill
Posts: 124
Joined: 13 May 2016, 02:23

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

03 Apr 2021, 11:31

chaoscreater wrote:
01 Apr 2021, 22:34
I have 2 PCs with 2 different maximum screen resolutions. PC1 has 1920x1080 and PC2 has 1366x768. PC1 is my primary machine, which I use the most.

Let's say on PC1, I take a screen capture using Findtext and the automatically generated code works fine on PC1. Is there an easy way to make this code work for PC2, considering that it has a lower maximum screen resolution? I don't want to have to do multiple screen captures on 2 different machines (and possibly more). I'd like to just generate a piece of code and have it work across machines.
I'm facing the same problem... need help pls:D
User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

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

03 Apr 2021, 20:40

It is not too much hassle to retrieve "Text" on each machine! And then combine them to work on both machines:

Code: Select all

;Text1:="|<HighRes>*153$10.2EMXdyLtTZCYMUYU"
;Text2:="|<LowRes>*164$20.0AA073U3kQ1w3UzAMTnbzwMzz7DzknzwAzz7DzlX7wtkzAM7kC0w7073U0kkU"
Text:="|<HighRes>*153$10.2EMXdyLtTZCYMUYU|<LowRes>*164$20.0AA073U3kQ1w3UzAMTnbzwMzz7DzknzwAzz7DzlX7wtkzAM7kC0w7073U0kkU"
All the other code remains the same!
Otherwise it would be quite difficult and unreliable...
chaoscreater
Posts: 59
Joined: 12 Sep 2019, 21:15

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

06 Apr 2021, 16:19

And if you have 20 different machines with different resolutions? That won't be a scalable solution.

Also, if you don't limit the capture to a specific region/area, it'll perform slow. All my Findtext has the coordinates of the captured area and this will be different on machines with different resolutions.
jrigle
Posts: 1
Joined: 06 Apr 2021, 19:08

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

06 Apr 2021, 19:15

is this possible to only search for the shape? I mean only the shape of the image color not included
chaoscreater
Posts: 59
Joined: 12 Sep 2019, 21:15

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

06 Apr 2021, 21:41

I can't get ScreentoWindow to work. It's not giving me the correct output at all. I'm trying to click on an icon in the bottom right traybar. The Window coordinate is 1613, 42. Screen coordinate is 1613, 1064.

I'm getting 1621, 1072 for Window coordinate and 1613, 1064 for Screen coordinate.

Code: Select all

^+y::
{
	; #Include <FindText>

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

	BluetoothBatteryIcon:="|<>*153$23.zzzzzzzzzzzzzVzzs0TzryzzixzzQvzyurzxKjzv/TzrCzzghzzJfzyurzxnjzvjTzryzzU1zzzzzzzzzzzzzzzzk"

	 if (ok:=FindText(1543, 1017, 1799, 1075, 0, 0, BluetoothBatteryIcon))
	 {
	   
	   X:=ok.1.x, Y:=ok.1.y, Comment:=ok.1.id
	   
	   
	    msgbox, %X%, %Y%


	   
	   FindText.ScreenToWindow(x1:=ok.1.x, y1:=ok.1.y)
	   
	   msgbox %x1% %y1%

  
	 }

	 for i,v in ok
	   if (i<=2)
		 FindText.MouseTip(ok[i].x, ok[i].y)
	     
}
return


UPDATE:

Actually, I know what the issue is. Let's say my captured Findtext Image is somewhere in the center of the screen. Then the code above will return the correct coordinates for Window and Screen. However, if the FindText image is on the Windows bottom right traybar, then the coordinates are incorrect.

If you use Autohotkey WindowsSpy, you can see what I mean. If you click into one of the icons in the traybar, the Windows coordinate will change in WindowsSpy. If you click out of it, the coordinates will change again. It's hard to explain.
maleko48
Posts: 15
Joined: 19 Jul 2019, 13:35

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

07 Apr 2021, 16:29

chaoscreater wrote:
06 Apr 2021, 16:19
...
Also, if you don't limit the capture to a specific region/area, it'll perform slow. All my Findtext has the coordinates of the captured area and this will be different on machines with different resolutions.
If you set up your script correctly with a common set of global variables and/or write your own functions that simply call and make use of FindText, you can get pretty good results. WinGetPos is your friend to help narrow your search area to the Window's area only. On my function I wrote for using FindText to search and click for automation purposes, I have an "area" parameter where I can specify: "top" "left" "right" "bottom" "center" "topleft" "topright" "bottomleft" " bottomright" "top 1/4" "left 1/9" etc to speed up execution beyond only limiting to the window's search area.

Here is what I use in case it helps anyone in here (my workstation uses 3 monitors, but I am trying to make my script somewhat universal / distributable for those who work my same position at my company, but may be on slightly different hardware setups):

Code: Select all

SYS_WinClickTarget(WinName, Target, Xoff:=0, Yoff:=0, Mspd:=0, TXT_ERR:=0, BG_ERR:=0, Zone:="", ClickAll:=0, WhichButton:="")
{
	global TLX, TLY, BRX, BRY, H, W, Numerator, Denominator, X, Y
	
	SetTitleMatchMode, 2
	SetTitleMatchMode, Fast
	SetDefaultMouseSpeed, %Mspd%
	
	WinGetPos, TLX, TLY, W, H, %WinName%
	BRX:= TLX + W
	BRY:= TLY + H
	;MsgBox, INITIAL`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
	
	if (Zone != "")
		SYS_WinGetZone(Zone)	; THIS SETS THE GLOBAL VARS: TLX, TLY, BRX, BRY, Numerator, Denominator
	
	;MsgBox, POST-PROCESSING`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
	
	if (ClickAll == 0 && ok:=FindText(TLX, TLY, BRX, BRY, TXT_ERR, BG_ERR, Target))
	{
		CoordMode, Mouse
		X:=ok.1.x + Xoff, Y:=ok.1.y + Yoff, Comment:=ok.1.id
		if (WhichButton != "")
			Click, %X%, %Y%, %WhichButton%
		else
			Click, %X%, %Y%
	}
	
	else if (ClickAll == 1 && ok:=FindText(TLX, TLY, BRX, BRY, TXT_ERR, BG_ERR, Target))
	{
		CoordMode, Mouse
		for i,v in ok
			if (i<=ok.MaxIndex())
			{
				X:=ok[i].x + Xoff, Y:=ok[i].y + Yoff, Comment:=ok[i].id
				if (WhichButton != "")
					Click, %X%, %Y%, %WhichButton%
				else
					Click, %X%, %Y%
			}
	}
	
	else if (ClickAll == -1 && ok:=FindText(TLX, TLY, BRX, BRY, TXT_ERR, BG_ERR, Target))
	{
		CoordMode, Mouse
		for i,v in ok
			if (i<=ok.MaxIndex())
			{
				X:=ok[i].x + Xoff, Y:=ok[i].y + Yoff, Comment:=ok[i].id
				MouseMove, %X%, %Y%
			}
	}
}

Code: Select all

SYS_WinGetZone(str)
{
	global TLX, TLY, BRX, BRY, H, W, Numerator, Denominator
	
	ZoneArray:= StrSplit(str, A_SPACE)
	Zone:= ZoneArray[1]
	Frac:= ZoneArray[2]
	if (Frac != "")
	{
		Fraction:= StrSplit(Frac,"/")
		Numerator:= Fraction[1]
		Denominator:= Fraction[2]
	}
	;MsgBox, Zone=%Zone% `nFrac=%Frac% `nNumer:%Numerator% `nDenom:%Denominator%
	
	if (Zone = "TOP" || Zone = "T")
	{
		TLX:= TLX, TLY:= TLY
		;MsgBox, TOP`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		if (Frac != "")
		{
			BRX:= TLX + W
			BRY:= TLY + (H / Denominator)
			;MsgBox, TOP-MOD`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		}
		;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
	}
	else if (Zone = "LEFT" || Zone = "L")
	{
		TLX:= TLX, TLY:= TLY
		;MsgBox, LEFT`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		if (Frac != "")
		{
			BRX:= TLX + (W / Denominator)
			BRY:= TLY + H
			;MsgBox, LEFT-MOD`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		}
		;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
	}
	else if  (Zone = "BOTTOM" || Zone = "B")
	{
		BRX:= TLX + W, BRY:= TLY + H
		;MsgBox, BOTTOM`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		if (Frac != "")
		{
			TLX:= TLX
			TLY:= (TLY + H) - (H / Denominator)
			;MsgBox, BOTTOM-MOD`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		}
		;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
	}
	else if  (Zone = "RIGHT" || Zone = "R")
	{
		BRX:= TLX + W, BRY:= TLY + H
		;MsgBox, RIGHT`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		if (Frac != "")
		{
			TLX:= (TLX + W) - (W / Denominator)
			TLY:= TLY
			;MsgBox, RIGHT-MOD`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		}
		;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
	}
	else if (Zone  = "TOPLEFT" || Zone = "TL")
	{
		TLX:= TLX, TLY:= TLY, BRX:= TLX + ((1/4) * W), BRY:= TLY + ((1/4) * H)
		;MsgBox, TOPLEFT`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
	}
	else if (Zone  = "BOTTOMLEFT" || Zone = "BL")
	{
		TLX:= TLX, TLY:= TLY + ((3/4) * H), BRX:= TLX + ((1/4) * W), BRY:= TLY + H
		;MsgBox, BOTTOMLEFT`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
	}
	else if (Zone  = "BOTTOMRIGHT" || Zone = "BR")
	{
		TLX:= TLX + ((3/4) * W), TLY:= TLY + ((3/4) * H), BRX:= TLX + W, BRY:= TLY + H				
		;MsgBox, BOTTOMRIGHT`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
	}
	else if (Zone  = "TOPRIGHT" || Zone = "TR")
	{
		TLX:= TLX + ((3/4) * W), TLY:= TLY, BRX:= TLX + W, BRY:= TLY + ((1/4) * H)
		;MsgBox, TOPRIGHT`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
	}
	else if (Zone  = "CENTER" || Zone = "CTR")
	{
		TLX:= TLX + ((1/3) * W), TLY:= TLY + ((1/3) * H), BRX:= TLX + ((2/3) * W), BRY:= TLY + ((2/3) * H)
		;MsgBox, CENTER`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
	}
}
It is coded pretty primitively and not very efficiently as I work on this in between answering calls at my day job, lol. (I automate as much as possible of our Citrix-based apps that stream from a remote machine completely optically using FindText and keyboard macros alone.) Major thanks to @feiyue and his algorithms that deal with streaming artifacts so well! Also, I have noticed that FindText v8.4 runs faster and more consistently than the v7.7 I was previously using. :)
chaoscreater
Posts: 59
Joined: 12 Sep 2019, 21:15

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

07 Apr 2021, 22:24

maleko48 wrote:
07 Apr 2021, 16:29
chaoscreater wrote:
06 Apr 2021, 16:19
...
Also, if you don't limit the capture to a specific region/area, it'll perform slow. All my Findtext has the coordinates of the captured area and this will be different on machines with different resolutions.
If you set up your script correctly with a common set of global variables and/or write your own functions that simply call and make use of FindText, you can get pretty good results. WinGetPos is your friend to help narrow your search area to the Window's area only. On my function I wrote for using FindText to search and click for automation purposes, I have an "area" parameter where I can specify: "top" "left" "right" "bottom" "center" "topleft" "topright" "bottomleft" " bottomright" "top 1/4" "left 1/9" etc to speed up execution beyond only limiting to the window's search area.

Here is what I use in case it helps anyone in here (my workstation uses 3 monitors, but I am trying to make my script somewhat universal / distributable for those who work my same position at my company, but may be on slightly different hardware setups):

Code: Select all

SYS_WinClickTarget(WinName, Target, Xoff:=0, Yoff:=0, Mspd:=0, TXT_ERR:=0, BG_ERR:=0, Zone:="", ClickAll:=0, WhichButton:="")
{
	global TLX, TLY, BRX, BRY, H, W, Numerator, Denominator, X, Y
	
	SetTitleMatchMode, 2
	SetTitleMatchMode, Fast
	SetDefaultMouseSpeed, %Mspd%
	
	WinGetPos, TLX, TLY, W, H, %WinName%
	BRX:= TLX + W
	BRY:= TLY + H
	;MsgBox, INITIAL`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
	
	if (Zone != "")
		SYS_WinGetZone(Zone)	; THIS SETS THE GLOBAL VARS: TLX, TLY, BRX, BRY, Numerator, Denominator
	
	;MsgBox, POST-PROCESSING`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
	
	if (ClickAll == 0 && ok:=FindText(TLX, TLY, BRX, BRY, TXT_ERR, BG_ERR, Target))
	{
		CoordMode, Mouse
		X:=ok.1.x + Xoff, Y:=ok.1.y + Yoff, Comment:=ok.1.id
		if (WhichButton != "")
			Click, %X%, %Y%, %WhichButton%
		else
			Click, %X%, %Y%
	}
	
	else if (ClickAll == 1 && ok:=FindText(TLX, TLY, BRX, BRY, TXT_ERR, BG_ERR, Target))
	{
		CoordMode, Mouse
		for i,v in ok
			if (i<=ok.MaxIndex())
			{
				X:=ok[i].x + Xoff, Y:=ok[i].y + Yoff, Comment:=ok[i].id
				if (WhichButton != "")
					Click, %X%, %Y%, %WhichButton%
				else
					Click, %X%, %Y%
			}
	}
	
	else if (ClickAll == -1 && ok:=FindText(TLX, TLY, BRX, BRY, TXT_ERR, BG_ERR, Target))
	{
		CoordMode, Mouse
		for i,v in ok
			if (i<=ok.MaxIndex())
			{
				X:=ok[i].x + Xoff, Y:=ok[i].y + Yoff, Comment:=ok[i].id
				MouseMove, %X%, %Y%
			}
	}
}

Code: Select all

SYS_WinGetZone(str)
{
	global TLX, TLY, BRX, BRY, H, W, Numerator, Denominator
	
	ZoneArray:= StrSplit(str, A_SPACE)
	Zone:= ZoneArray[1]
	Frac:= ZoneArray[2]
	if (Frac != "")
	{
		Fraction:= StrSplit(Frac,"/")
		Numerator:= Fraction[1]
		Denominator:= Fraction[2]
	}
	;MsgBox, Zone=%Zone% `nFrac=%Frac% `nNumer:%Numerator% `nDenom:%Denominator%
	
	if (Zone = "TOP" || Zone = "T")
	{
		TLX:= TLX, TLY:= TLY
		;MsgBox, TOP`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		if (Frac != "")
		{
			BRX:= TLX + W
			BRY:= TLY + (H / Denominator)
			;MsgBox, TOP-MOD`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		}
		;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
	}
	else if (Zone = "LEFT" || Zone = "L")
	{
		TLX:= TLX, TLY:= TLY
		;MsgBox, LEFT`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		if (Frac != "")
		{
			BRX:= TLX + (W / Denominator)
			BRY:= TLY + H
			;MsgBox, LEFT-MOD`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		}
		;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
	}
	else if  (Zone = "BOTTOM" || Zone = "B")
	{
		BRX:= TLX + W, BRY:= TLY + H
		;MsgBox, BOTTOM`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		if (Frac != "")
		{
			TLX:= TLX
			TLY:= (TLY + H) - (H / Denominator)
			;MsgBox, BOTTOM-MOD`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		}
		;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
	}
	else if  (Zone = "RIGHT" || Zone = "R")
	{
		BRX:= TLX + W, BRY:= TLY + H
		;MsgBox, RIGHT`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		if (Frac != "")
		{
			TLX:= (TLX + W) - (W / Denominator)
			TLY:= TLY
			;MsgBox, RIGHT-MOD`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		}
		;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
	}
	else if (Zone  = "TOPLEFT" || Zone = "TL")
	{
		TLX:= TLX, TLY:= TLY, BRX:= TLX + ((1/4) * W), BRY:= TLY + ((1/4) * H)
		;MsgBox, TOPLEFT`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
	}
	else if (Zone  = "BOTTOMLEFT" || Zone = "BL")
	{
		TLX:= TLX, TLY:= TLY + ((3/4) * H), BRX:= TLX + ((1/4) * W), BRY:= TLY + H
		;MsgBox, BOTTOMLEFT`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
	}
	else if (Zone  = "BOTTOMRIGHT" || Zone = "BR")
	{
		TLX:= TLX + ((3/4) * W), TLY:= TLY + ((3/4) * H), BRX:= TLX + W, BRY:= TLY + H				
		;MsgBox, BOTTOMRIGHT`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
	}
	else if (Zone  = "TOPRIGHT" || Zone = "TR")
	{
		TLX:= TLX + ((3/4) * W), TLY:= TLY, BRX:= TLX + W, BRY:= TLY + ((1/4) * H)
		;MsgBox, TOPRIGHT`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
	}
	else if (Zone  = "CENTER" || Zone = "CTR")
	{
		TLX:= TLX + ((1/3) * W), TLY:= TLY + ((1/3) * H), BRX:= TLX + ((2/3) * W), BRY:= TLY + ((2/3) * H)
		;MsgBox, CENTER`n`nTLX:`t%TLX%`t`tTLY:`t%TLY%`nW:`t%W%`t`tH:`t%H%`nBRX:`t%BRX%`tBRY:`t%BRY%
		;return {TLX: %TLX%, TLY: %TLY%, BRX: %BRX%, BRY: %BRY%}
	}
}
It is coded pretty primitively and not very efficiently as I work on this in between answering calls at my day job, lol. (I automate as much as possible of our Citrix-based apps that stream from a remote machine completely optically using FindText and keyboard macros alone.) Major thanks to @feiyue and his algorithms that deal with streaming artifacts so well! Also, I have noticed that FindText v8.4 runs faster and more consistently than the v7.7 I was previously using. :)





Sorry, I'm not sure I understand what you mean. I wase talking talking about getting a Findtext image adjusted to work on machines with different resolutions. Let's say you have 2 machines, one with a super low resolution and another with an ultra high resolution. The same image will be displayed differently on both machines. The size of the image is different and the coordinate on the screen is different.
image.png
image.png (2.98 KiB) Viewed 2910 times
Clearly, if you take a Findtext image on either of the machine, it won't be matched on another, because the image is either too big or too small. Furthermore, the Findtext captured area coordinates do not translate across the machines.
maleko48
Posts: 15
Joined: 19 Jul 2019, 13:35

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

08 Apr 2021, 09:25

chaoscreater wrote:
07 Apr 2021, 22:24
Sorry, I'm not sure I understand what you mean. I wase talking talking about getting a Findtext image adjusted to work on machines with different resolutions. Let's say you have 2 machines, one with a super low resolution and another with an ultra high resolution. The same image will be displayed differently on both machines. The size of the image is different and the coordinate on the screen is different.

image.png

Clearly, if you take a Findtext image on either of the machine, it won't be matched on another, because the image is either too big or too small. Furthermore, the Findtext captured area coordinates do not translate across the machines.
What exactly is it that you are trying to accomplish?

Aside from resolution settings, custom fonts or even Windows' ClearText technology could also be enough to break compatibility and scalability across a wider range of hardware. If that's what you are up against, this may be the wrong tool for the job.

If you were really set on it, you could conceivably write an algorithm that slices and dices a master "calibration image" taken from a target machine meant to dynamically re-create its OCR library of objects to match against (ie. A thru Z and 0 thru 9 along with some common symbols and such).

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: tidbit and 105 guests