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 Feb 2021, 11:06

Updated to 8.1 version - 2021/02/19 :beer: :dance:
.... 1. Add: since all the input and output coordinates of the FindText function are relative to the screen,
....... You can use the following functions to convert coordinates to relative window coordinates:
....... WindowToScreen(), ScreenToWindow(), ClientToScreen(), ScreenToClient().
.... 2. Modify: previously, the binding window could not be moved beyond the screen range,
....... otherwise it would not be found. Now this problem has been fixed.

@chaoscreater Now you can change the coordinates yourself. :D
Avastgard
Posts: 133
Joined: 30 Sep 2016, 21:54

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

19 Feb 2021, 20:24

I'm getting an error message when I try to run the latest version:
---------------------------
FindText Tool.ahk
---------------------------
Error: Call to nonexistent function.

Specifically: WindowToScreen(dx:=0, dy:=0, id), x-=dx, y-=dy

Line#
1102: SetTimer,,Off
1103: }
1107: {
1108: WinGetPos,winx,winy,,,id ? "ahk_id " id : "A"
1109: x+=Floor(winx), y+=Floor(winy)
1110: }
1113: {
---> 1114: WindowToScreen(dx:=0, dy:=0, id), x-=dx, y-=dy
1115: }
1118: {
1119: if (!id)
1120: WinGet,id,ID,A
1121: VarSetCapacity(pt,8,0), NumPut(0,pt,"int64"), DllCall("ClientToScreen","Ptr",id,"Ptr",&pt), x+=NumGet(pt,"int"), y+=NumGet(pt,4,"int")
1124: }
1127: {

The program will exit.
---------------------------
OK
---------------------------
feiyue
Posts: 349
Joined: 08 Aug 2014, 04:08

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

19 Feb 2021, 21:00

@Avastgard
Fixed it! Thank you for your feedback.
Avastgard
Posts: 133
Joined: 30 Sep 2016, 21:54

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

23 Feb 2021, 03:55

You're welcome.

This is such a great tool!
feiyue
Posts: 349
Joined: 08 Aug 2014, 04:08

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

03 Mar 2021, 11:53

Updated to 8.2 version - 2021/03/03 :dance: :beer:
1. Add: Added a search direction (dir = 5): From the Center to all around.
2. Modify: The size of machine code is reduced.
Qhimin
Posts: 16
Joined: 30 Nov 2020, 19:24

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

07 Mar 2021, 19:24

Hello Feiyue,

Is this function supposed to work with AHK_H ? Cause I'm trying to make it work there to get the text codes but just after I run the .ahk nothing happens.

Thank you!
feiyue
Posts: 349
Joined: 08 Aug 2014, 04:08

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

08 Mar 2021, 00:34

@Qhimin
Maybe this is a BUG of Ahk_H version, you can try like this:

Code: Select all

Gui(cmd, arg1:="")
{
  ;--  local  ;--  Comment out or remove this line
  static
Qhimin
Posts: 16
Joined: 30 Nov 2020, 19:24

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

08 Mar 2021, 05:54

feiyue wrote:
08 Mar 2021, 00:34
@Qhimin
Maybe this is a BUG of Ahk_H version, you can try like this:

Code: Select all

Gui(cmd, arg1:="")
{
  ;--  local  ;--  Comment out or remove this line
  static
Thank you very much @feiyue ! It does worked!
denysy1
Posts: 3
Joined: 08 Mar 2021, 12:57

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

08 Mar 2021, 13:07

Thanks for posting this.
Last edited by denysy1 on 08 Mar 2021, 14:56, edited 2 times in total.
gregster
Posts: 8916
Joined: 30 Sep 2013, 06:48

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

08 Mar 2021, 13:21

denysy1 wrote:
08 Mar 2021, 13:07
Wanted to point out, I'm getting an error with the latest version:

[indent=]Error at line 1368.

Line Text: Switch cmd
Error: This line does not contain a recognized action.
Your AHK version is too old, update it - switch was a relatively recent addition.
denysy1
Posts: 3
Joined: 08 Mar 2021, 12:57

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

08 Mar 2021, 18:18

I'm testing out this script. I've encountered some weird behavior:

When trying to run the script to recognize some text in a program that if running in full-screen mode, the script does find the text, but when I try to move the mouse to the reported co-ordinates, it moves to some to a wrong location. What's even more interesting is that the offset from the correct location is not consistent. Depending on where on the screen the text appears, the offset is different. Any suggestion on what could be causing this behavior?
feiyue
Posts: 349
Joined: 08 Aug 2014, 04:08

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

08 Mar 2021, 20:53

@denysy1 you can change the coordinates yourself. :D

All the input and output coordinates of the FindText function are relative to the screen,
You can use the following functions to convert coordinates to relative window coordinates:
WindowToScreen(), ScreenToWindow(), ClientToScreen(), ScreenToClient().
Dillweed
Posts: 5
Joined: 10 Oct 2020, 12:33

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

12 Mar 2021, 18:34

Hello there. I need to search for an image that is bigger than 50 x 50. How can I do that?

Also what is the difference between Capture and CaptureS?

Thanks for the continued work on this script!
DoriTos_
Posts: 16
Joined: 15 Mar 2021, 08:30

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

15 Mar 2021, 09:21

Dillweed wrote:
12 Mar 2021, 18:34
Hello there. I need to search for an image that is bigger than 50 x 50. How can I do that?

Also what is the difference between Capture and CaptureS?

Thanks for the continued work on this script!
I'm also wanting this, i've tried to put a higher value but doesn't work
feiyue
Posts: 349
Joined: 08 Aug 2014, 04:08

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

15 Mar 2021, 21:05

@Dillweed
Although there is no detailed explanation, but you can touch more to understand each function,
as long as the mouse moves to each control, there will be a function prompt.

Expand the size of the selection box to adjust the width and height of the main interface and click apply.
The CaptureS function is used with hotkeys to capture pictures, and the screenshot hotkeys are also set in the main interface.
Dillweed
Posts: 5
Joined: 10 Oct 2020, 12:33

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

17 Mar 2021, 09:45

@feiyue
I'm sorry, I'm not sure that I understand what you are saying, but I think I found a workaround by taking two captures and then doing work on those captures.

Really, I was hoping to find a way to capture an area of 100 x 12. Is that possible without capturing two areas?
feiyue
Posts: 349
Joined: 08 Aug 2014, 04:08

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

18 Mar 2021, 01:20

Expand the size of the selection box to adjust the width:35 and height:12 of the main interface and click apply.
adjust “ Height:12 ” to “ Height:50 ”, The actual height is 101 (2*50+1).
feiyue
Posts: 349
Joined: 08 Aug 2014, 04:08

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

18 Mar 2021, 18:18

Updated to 8.3 version - 2021/03/19 :dance: :beer:
.... 1. Add: Now You can set the capture mouse when capturing an image Use FindText.CaptureCursor(1) .
.... 2. Add: The FindText.ImageSearch() function is added, which is completely similar to
....... the built-in command ImageSearch, The coordinates are set by "CoordMode, Pixel" .
.... 3. Add: A new ScreenShot selection window has been added.
....... Now you can get multiple screenshots using hotkeys,
....... and then click the "CaptureS" button to select which screenshot to restore.
Hagork
Posts: 1
Joined: 18 Mar 2021, 22:34

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

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?

Got it working

Code: Select all

 if (ok:=FindText(407, 184, 521, 660, 0, 0, Text))
 {
   CoordMode, Mouse
   X:=ok.1.x, Y:=ok.1.y, Comment:=ok.1.id
	   Click, %X% %Y% 0
 	   Pause
  }
   Else
  	 Sleep, 100
User avatar
ivill
Posts: 124
Joined: 13 May 2016, 02:23

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

19 Mar 2021, 03:08

Hi, need help please, how do i manage to work with multiple monitors?
I've got a laptop and sometimes work with an external monitor, and it won't work with different monitors,
for this situation, do you have some advice to solve the problem? thanks very much!

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: Auntiejack56 and 128 guests