FindText, how to use WindowToScreen() helper function with FindText()? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Ralf_Reddings200244
Posts: 84
Joined: 11 Mar 2023, 14:16

FindText, how to use WindowToScreen() helper function with FindText()?

Post by Ralf_Reddings200244 » 31 Mar 2023, 13:23

I have been messing around with FindText Library by user feiyue, link to library HERE, I am stuck on using one of its helper functions, I wonder someone who is familiar with it can help me.

Currently I can find a graphic, the number 4, by using the following:

Code: Select all

#Include <FindText>
F1::
t1:=A_TickCount, Text:=X:=Y:=""
Text:="|<4>[b]50$6.66CCKqz66U"
if (ok:=FindText(X, Y, 1407-150000, 1196-150000, 1407+150000, 1196+150000, 0, 0, Text))
{
}
MsgBox, 4096, Tip, % "Found:`t" Round(ok.Length())
  . "[c]n[/c]nTime:`t" (A_TickCount-t1) " ms"
  . "[c]n[/c]nPos:`t" ok[1].x ", " ok[1].y
  . "[c]n[/c]nResult:`t<" (Comment:=ok[1].id) ">"
for i,v in ok  ; ok value can be get from ok:=FindText().ok
  if (i<=2)
    FindText().MouseTip(ok[i].x, ok[i].y)
But the above uses screen coordinates, so it matches a bunch of other ones all over the my array of monitors, even the target window. its also slow, I have 4 monitors.

I tried a test where I specified a very limited range of coordinates in if (ok:=FindText(X, Y,,,,, 0, 0, Text)) it was able to find it much faster 10ms. But using hardcoded coordinates is not ideal as I am constantly moving this window.

Reading the various articles for this library, I found there is a helper function for this exact need, FindText().WindowToScreen(outX2, outY2, 200, 300).
The help I was able to find on the function mentions:
>FindText().WindowToScreen(outX2, outY2, 200, 300) If ahk_id is not specified, then the active window will be used
my goal is to get the script to only look at the active windows body, when searching for a graphic

But I am struggling to actually get a working example using my previous code:

Code: Select all

#Include <FindText>
F1::
t1:=A_TickCount, Text:=X:=Y:=""
Text:="|<4>[/b]50$6.66CCKqz66U"
;if (ok:=FindText(X, Y, 1407-150000, 1196-150000, 1407+150000, 1196+150000, 0, 0, Text))
;if (ok:=FindText(X, Y, outX2, outY2, 777, 236, 0, 0, Text).WindowToScreen(outX2, outY2, 777, 236))
if (ok:=FindText(outX2,outY2, , , , , 0, 0, Text).WindowToScreen(outX2, outY2, 775, 60))
{
}
MsgBox, 4096, Tip, % "Found:`t" Round(ok.Length())
  . "[c]n[/c]nTime:`t" (A_TickCount-t1) " ms"
  . "[c]n[/c]nPos:`t" ok[1].x ", " ok[1].y
  . "[c]n[/c]nResult:`t<" (Comment:=ok[1].id) ">"
for i,v in ok  ; ok value can be get from ok:=FindText().ok
  if (i<=2)
    FindText().MouseTip(ok[i].x, ok[i].y)
The script fails to find the graphic, I have tried a bunch of variations but nothing works.

I am out of ideas here, so any help would be great. Thanks.

Descolada
Posts: 1098
Joined: 23 Dec 2021, 02:30

Re: FindText, how to use WindowToScreen() helper function with FindText()?  Topic is solved

Post by Descolada » 31 Mar 2023, 14:27

If you want to limit the search to only a certain window, then you need to get that windows location with WinGetPos and use those coordinates in FindText.

Code: Select all

WinGetPos, winX, winY, winW, winH, Title of the window of interest
FindText(X, Y, winX, winY, winX+winW, winY+winH, 0, 0, Text)
FindText().WindowToScreen() on the other hand converts coordinates relative to the window to coordinates relative to the screen. In window coordinates the left top corner of the window is (0,0). You can read more about CoordMode from the docs. I don't think you need to use that function in this case.

Ralf_Reddings200244
Posts: 84
Joined: 11 Mar 2023, 14:16

Re: FindText, how to use WindowToScreen() helper function with FindText()?

Post by Ralf_Reddings200244 » 01 Apr 2023, 10:54

I think I confused myself there, thanks so much for the clarification and solution

Post Reply

Return to “Ask for Help (v1)”