FindText - Capture screen image into text and then find it

Post your working scripts, libraries and tools
JohnCarrott80
Posts: 2
Joined: 03 Sep 2020, 01:26

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

03 Sep 2020, 01:32

I'm having trouble running a script including FindText.ahk...I can run the GUI just fine, but when importing it into another script, it breaks...I'm on version 1.1.33.02 (most recent version)...This is the error I get. I copied it directly from the OP multiple times and it gives me the error every time.
20200903_022505.jpg
20200903_022505.jpg (68.46 KiB) Viewed 844 times
User avatar
rommmcek
Posts: 1097
Joined: 15 Aug 2014, 15:18

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

03 Sep 2020, 02:14

Try either to comment the line like: ; #Include "D:\Documents\Lib\FindText.ahk"

or comment the function like:

Code: Select all

/*
;===== Copy The Following Functions To Your Own Code Just once =====


;--------------------------------
;  FindText - Capture screen image into text and then find it
…
JohnCarrott80
Posts: 2
Joined: 03 Sep 2020, 01:26

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

03 Sep 2020, 02:48

rommmcek wrote:
03 Sep 2020, 02:14
Try either to comment the line like: ; #Include "D:\Documents\Lib\FindText.ahk"

or comment the function like:

Code: Select all

/*
;===== Copy The Following Functions To Your Own Code Just once =====


;--------------------------------
;  FindText - Capture screen image into text and then find it
…
When I comment out the #Include line, it no longer gives an error, but it obviously also doesn't do anything. Something about loading the script is messing up ahk...could it be formatting errors when copying it to a text file from the OP? I've deleted the file and copied the OP to a new file multiple times, but with no change...What's really weird is that even when I delete everything in the file except for a blank FindText(){} function, it still gives the same error...When loading a different script, it gives no error, but loading this script even once seems to doom the file holding it to eternal errors...this is really hurting my brain lol. I've loaded scripts in the past, and have never had this issue...I've tried stripping down the script to absolutely nothing except for a blank file that used to hold the script, and an #Include <BlankScript> line, and it gives the same error...starting fresh with a new blank file works, but once I copy in the code from the OP, that file never seems to load anymore and gives me this same error, no matter what the contents is...
feiyue
Posts: 236
Joined: 08 Aug 2014, 04:08

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

03 Sep 2020, 04:54

Error: Functions cannot contain functions.
eg:
a() {

b() {
}

; or #Include <FindText>

}
gandalfgarfield
Posts: 29
Joined: 20 Jun 2020, 22:27

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

05 Sep 2020, 08:14

@feiyue Hello Feiyue, Very nice script!!!!. I have a question tho. I tried using it on a certain game and it didn't work. Ive tried putting some simple script like Msgbox with your findtext script and its not working. do you have any workaround for this?
songdg
Posts: 168
Joined: 04 Oct 2017, 20:04

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

07 Sep 2020, 02:12

Image
How to use this tool to detect "2018-07-19" form date, I want to find how many dates on the left and right.Before 2020, I count how many "20" on the left and on the right, enter the year of 2020 it no longer works.
GridVin
Posts: 1
Joined: 24 Jul 2020, 20:21

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

15 Sep 2020, 04:06

Hi feiyue! Is it possible to run FindText() on an inactive window? If yes, can you show me how? Appreciate and thanks a lot mate.
LunarSummer
Posts: 3
Joined: 27 Sep 2020, 20:38

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

29 Sep 2020, 01:59

What are the returned coordinates relative to? I'm searching for an image which appears on another monitor. The coordinates returned are on the wrong monitor but if the monitor was overlapped and scaled it could be the correct position. How can I convert these?

For this example the returned coords are 1253, 376. And the WindowCoords are 3014, -106. The actual icon I'm looking for appears at screen coords 3202, 566 (I'm using 3 monitors)

Code: Select all

#SingleInstance,Force
#Include <FindText>
SetMouseDelay,-1
SetTitleMatchMode, 2
CoordMode, Mouse, Screen
CoordMode, Pixel, Screen
SetTitleMatchMode, 2
SetControlDelay -1
DetectHiddenWindows On
SetWorkingDir, %A_ScriptDir%

Loop
{	
	
	SysGet, TopX, 76
	SysGet, TopY, 77
	SysGet, VirtualWidth, 78
	SysGet, VirtualHeight, 79
	WinActivate, BlueStacks
	WinGetPos, winX, winY,,, BlueStacks
	
	t1:=A_TickCount, X:=Y:=""
	
	Text:="|<mauler>*141$41.wDUT1w7kC7XVkDUAF8l0D01DQU0Q04qYW0s2/BYU0k0YlZ0101G188202Y3EE40582Y0Dy+E19TzwEEG3zzwYl97zzsYYGDzzl5/8zzzl6MVzzyF025zzs0UMFzzUUVV1zy0F241zs0m4E1zU3Y9k1zU7cGk3z0RkxUDz1zVnUz"
	
	if (ok:=FindText(TopX, TopY, VirtualWidth, VirtualHeight,0,0,Text))
	{
	   ;CoordMode, Mouse
		CoordMode, Mouse, Screen 
		X:= ok.1.1, Y:= ok.1.2, W:= ok.1.3, H:= ok.1.4
 		mousemove, %X%, %Y%
	}
	
	MsgBox, 4096, Tip, % "Found :`t" Round(ok.MaxIndex())
	  . "`n`nTime  :`t" (A_TickCount-t1) " ms"
	  . "`n`nPos   :`t" X ", " Y ", " W ", " H
	  . "`n`nWindowCoords:`t" winX ", " winY
	  . "`n`nResult:`t" (ok ? "Success !" : "Failed !")	
	
	MouseGetPos, MouseX, MouseY
	ToolTip, "Mouse pos:" %MouseX% %MouseY%
}
Sperk
Posts: 2
Joined: 29 Sep 2020, 08:45

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

29 Sep 2020, 08:56

I've been working with this great script for a few days now and everything worked out fine. Today the script starts without any content in the two big textboxes. Capture, Test, Get Range, etc... work fine but in the end I get no output in the main window. AHK runs fine, other scripts too.I rebooted the computer and downloaded and started the script several times, but unfortunately without success.

Does anyone have a solution to the problem?

versions:
AutoHotkey v1.1.33.02
FindText 7.5


Update:
Now the script works again - it could be that it was related to the changed height and width, unfortunately I could not reproduce the error despite much "playing around". But as mentioned before: THANK YOU for the great script.
reluct
Posts: 95
Joined: 28 Nov 2018, 05:07

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

04 Oct 2020, 00:12

Hi, I use this code, but now i need change clicking coordinates, so it must click not on center of finding image. What i need add to code?

Code: Select all

   X:=ok.1.x, Y:=ok.1.y, Comment:=ok.1.id
   Click, %X%, %Y%
I see this commands:
offsetX, offsetY --> Set the Max text offset for combination lookup
; ruturn --> the function returns a second-order array
; containing all lookup results, Any result is an associative array
; {1:X, 2:Y, 3:W, 4:H, x:X+W//2, y:Y+H//2, id:Comment},

but how use it?
User avatar
rommmcek
Posts: 1097
Joined: 15 Aug 2014, 15:18

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

04 Oct 2020, 00:33

Where do you want to click?
To see the content of the ok array you can use:

Code: Select all

MsgBox % txtArr(ok)

txtArr(r, i:="  ", d:=0, b:="") {
	For k, v in r
		c.= IsObject(v)? b k ":`n" txtArr(v, i, d+1, b i): b k ": " v "`n", d>0? "": t:=c
    Return d>0? c: t
}
reluct
Posts: 95
Joined: 28 Nov 2018, 05:07

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

04 Oct 2020, 00:41

@rommmcek

Code: Select all

q::
; #Include <FindText>
Loop
{
 t1:=A_TickCount, X:=Y:=""

Text:="|<>[email protected]$1.k"

 if (ok:=FindText(714-150000, 375-150000, 714+150000, 375+150000, 0, 0, Text))

 {
   X:=ok.1.x, Y:=ok.1.y, Comment:=ok.1.id
   Click, %X%, %Y%
   sleep 500
   Send {Enter}
   Sleep 500
   Send {Right}
   Sleep 500
   Send {Backspace}
   sleep 500
   Send {LCtrl Down}{sc22}{LCtrl Up}
 }
 else if !(ok:=FindText(714-150000, 375-150000, 714+150000, 375+150000, 0, 0, Text))
  Send {WheelDown}
}
 return
In practice, I need to find one color pixel, and move the click point slightly. You can look on the screenshot http://prntscr.com/usri85
It clicks where the red arrow shows, right after the word look before the comma.
Last edited by reluct on 04 Oct 2020, 00:53, edited 1 time in total.
User avatar
rommmcek
Posts: 1097
Joined: 15 Aug 2014, 15:18

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

04 Oct 2020, 00:49

This will click ten pixels to the right:

Code: Select all

Click, % X+10 "," Y
reluct
Posts: 95
Joined: 28 Nov 2018, 05:07

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

04 Oct 2020, 01:11

@rommmcek
Sry but it's not work if need change X;Y

Code: Select all

Click, % X+10 "," % Y-30
User avatar
rommmcek
Posts: 1097
Joined: 15 Aug 2014, 15:18

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

04 Oct 2020, 01:16

Second % is redundant!

Code: Select all

Click, % X+10 "," Y-30
Dillweed
Posts: 1
Joined: 10 Oct 2020, 12:33

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

10 Oct 2020, 12:39

@feiyue

Hey fantastic script. It works wonders where imagesearch doesn't work. I was writing a script that runs and then exits and I found that when incorporating FindText into the script that the same script stays open. Is there a way for the script to exit after finding the image?

Thanks for the help,
Dillweed
JavierBO
Posts: 12
Joined: 08 Jul 2019, 05:43

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

13 Oct 2020, 19:39

Is it possible to get the Text in a simpler way?

Code: Select all

Text:="|<>[email protected]$1.k"
I made a program to find the Text on the screen and do something after. The problem is that everytime I open the program the image will be different.
It's getting annoying to capture, grayscale, center and then copy the Text to my own code everytime i use it.
Isn't there a better way to do it?
is it possible to just Right click on my desired place and that gives me the Text on clipboard without having to do all the rest?
feiyue
Posts: 236
Joined: 08 Aug 2014, 04:08

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

14 Oct 2020, 05:49

@JavierBO You can do this:

Code: Select all

#Include <FindText>

^RButton::
w:=10, h:=6
CoordMode, Mouse
MouseGetPos, x, y
KeyWait, RButton
s:=GetTextFromScreen(x-w,y-h,x+w,y+h)
Clipboard=if (ok:=FindText(0,0,150000,150000,0,0,"%s%"))
MsgBox, 4096,, Copy OK !, 0.5
return

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Google [Bot], NorInd and 15 guests