how do I make findtext choose the first of 2 identical images Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
maxkill
Posts: 158
Joined: 11 Apr 2016, 13:03

how do I make findtext choose the first of 2 identical images

Post by maxkill » 01 Feb 2023, 16:57

right now I can only get the closest image from shortening the search distance, but it is quite a problem a lot of times since it might be too short search distance then it finds none or if too far it searches the furthest one away instead of the closest one I want

any solution to increase search length and only choosing the first found image?

(second topic not as important another q below if can be answered:)
while I ask, any way to get coordinates of booth images and then click between them if both are identical (I know how to do it if they are different)

Baconfry
Posts: 14
Joined: 07 Jan 2022, 04:07

Re: how do I make findtext choose the first of 2 identical images

Post by Baconfry » 02 Feb 2023, 11:37

Your question is a bit hard to understand, but if you meant feiyue's amazing function, you can extend the boundaries of the search area with parameters 3, 4, 5, 6. It will stop when it finds the first image by default.

Code: Select all

;  returnArray := FindText(
;      OutputX --> The name of the variable used to store the returned X coordinate
;    , OutputY --> The name of the variable used to store the returned Y coordinate
;    , X1 --> the search scope's upper left corner X coordinates
;    , Y1 --> the search scope's upper left corner Y coordinates
;    , X2 --> the search scope's lower right corner X coordinates
;    , Y2 --> the search scope's lower right corner Y coordinates
;    , err1 --> Fault tolerance percentage of text       (0.1=10%)
;    , err0 --> Fault tolerance percentage of background (0.1=10%)
;    , Text --> can be a lot of text parsed into images, separated by "|"
;    , ScreenShot --> if the value is 0, the last screenshot will be used
;    , FindAll --> if the value is 0, Just find one result and return
;    , JoinText --> if you want to combine find, it can be 1, or an array of words to find
;    , offsetX --> Set the max text offset (X) for combination lookup
;    , offsetY --> Set the max text offset (Y) for combination lookup
;    , dir --> Nine directions for searching: up, down, left, right and center
;    , zoomW --> Zoom percentage of image width  (1.0=100%)
;    , zoomH --> Zoom percentage of image height (1.0=100%)
;  )
You can also adjust the search direction with the parameter dir to set the "first" image.
1 ==> ( Left to Right ) Top to Bottom
2 ==> ( Right to Left ) Top to Bottom
3 ==> ( Left to Right ) Bottom to Top
4 ==> ( Right to Left ) Bottom to Top
5 ==> ( Top to Bottom ) Left to Right
6 ==> ( Bottom to Top ) Left to Right
7 ==> ( Top to Bottom ) Right to Left
8 ==> ( Bottom to Top ) Right to Left
As for your second question, you can get the coordinates of both images by setting FindAll to 1 and using the return variable.

Code: Select all

;  If the return variable is set to "ok", ok[1] is the first result found.
;  ok[1][1], ok[1][2] is the X, Y coordinate of the upper left corner of the found image,
;  ok[1][3] is the width of the found image, and ok[1][4] is the height of the found image,
;  ok[1].x <==> ok[1][1]+ok[1][3]//2 ( is the Center X coordinate of the found image ),
;  ok[1].y <==> ok[1][2]+ok[1][4]//2 ( is the Center Y coordinate of the found image ),
;  ok[1].id is the comment text, which is included in the <> of its parameter.

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: how do I make findtext choose the first of 2 identical images

Post by Chunjee » 02 Feb 2023, 12:34

You can do your searches and if two results are found. That'll be the first two identical images.

maxkill
Posts: 158
Joined: 11 Apr 2016, 13:03

Re: how do I make findtext choose the first of 2 identical images

Post by maxkill » 03 Feb 2023, 11:03

Baconfry wrote:
02 Feb 2023, 11:37
text
managed to solve it

Code: Select all

coordmode, mouse, screen
MouseGetPos, xx, yy
sleep, 50
Text:="|<>[email protected]$8.TrzzTrxzTs"
Text.="|<>[email protected]$8.TrzzTrxzTs" ;same 2 images

if (ok:=FindText(xx-2000, yy+2400, xx, yy-2400, 0, 0, Text))

;if (ok:=FindText(X, Y, 0, 0, A_ScreenWidth, A_ScreenHeight, 0, 0, Text))  ; <== you can (Plus + or Minus -) anything from the search range as you know, e.g. (A_ScreenHeight /2)  or (A_ScreenHeight - yy) etc etc. You get the gist obviously. 
 ;~  ====> (pasted here just for reference)  ====>   MouseClick, Left, ((ok[1].x + ok[2].x) / 2), ((ok[1].y + ok[2].y ) / 2), 1, 1 
 
middleX := ((ok[1].x + ok[2].x) / 2) 
middleY := ((ok[1].y + ok[2].y) / 2)  
{
	MouseMove, middleX, middleY, 1
}	
;
Mousegetpos, xx, yy
sleep, 100
Text:="|<>[email protected]$8.TrzzTrxzTs"
if (ok:=FindText(xx+1200, yy-2500, xx+0, yy+2900, 0, 0, Text)) 
{
  xx:=ok.1.1, yy:=ok.1.2, w:=ok.1.3, h:=ok.1.4
  mousemove, xx, yy, 1
}

	

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: how do I make findtext choose the first of 2 identical images

Post by Chunjee » 03 Feb 2023, 13:07

makes more sense to me this way:

Code: Select all

queryStr := "|<>[email protected]$8.TrzzTrxzTs"
ok := FindText(xx+1200, yy-2500, xx+0, yy+2900, 0, 0, queryStr)
; mousemove if two identicle are found
if (ok.count() == 2) {
	mousemove, % ok.1.1, % ok.1.2, 1
}

maxkill
Posts: 158
Joined: 11 Apr 2016, 13:03

Re: how do I make findtext choose the first of 2 identical images  Topic is solved

Post by maxkill » 04 Feb 2023, 17:00

Chunjee wrote:
03 Feb 2023, 13:07
makes more sense to me this way:

Code: Select all

queryStr := "|<>[email protected]$8.TrzzTrxzTs"
ok := FindText(xx+1200, yy-2500, xx+0, yy+2900, 0, 0, queryStr)
; mousemove if two identicle are found
if (ok.count() == 2) {
	mousemove, % ok.1.1, % ok.1.2, 1
}
Very nice indeed. Any way to make it go for the first image found if both are not found? Because it messes up if both are not found


maxkill
Posts: 158
Joined: 11 Apr 2016, 13:03

Re: how do I make findtext choose the first of 2 identical images

Post by maxkill » 05 Feb 2023, 14:18

Chunjee wrote:
04 Feb 2023, 17:06
wouldn't that be else if (ok.count() == 1) { ?
Appears to be working great! Thanks! :thumbup:
final code

Code: Select all

MouseGetPos, xx, yy
sleep, 100
queryStr := "|<>[email protected]$8.TrzzTrxzTs"
ok := FindText(xx-3800, yy-2500, xx+1000, yy+2900, 0, 0, queryStr)
; mousemove if two identicle are found
if (ok.count() == 2) {
	mousemove, % ok.1.1+2, % ok.1.2+5, 1
send, {LButton Down}
}
else if (ok.count() == 1) 
{
mousemove, % ok.1.1+2, % ok.1.2+5, 1
send, {LButton Down}
}

Post Reply

Return to “Ask for Help (v1)”