Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

FindClick() 2nd Edition


  • Please log in to reply
66 replies to this topic
Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

Results := FindClick(MyImage, "n e") ; "n" tells FindClick to not click on the images

Loop, Parse, Results, `n
If (A_Index =1) { ; 1st image found
StringSplit, Coords, A_LoopField, `,
MsgBox, The coordinates are (%Coords1%,%Coords2%)
Break
}

MsgBox, The coordinates are (%Coords1%,%Coords2%)

 

Loop, Parse, Results, `n
If (A_Index =2) { ; 2nd image found
StringSplit, Coords, A_LoopField, `,
MsgBox, The coordinates are (%Coords1%,%Coords2%)
Break
}

MsgBox, The coordinates are (%Coords1%,%Coords2%)



penguin114
  • Members
  • 8 posts
  • Last active: Aug 10 2013 11:00 AM
  • Joined: 12 Jan 2013

It's Safmy.

 

Works once and then this pops up.

error_zpsded73520.png

 

And when I try the options like "Stay" this pops up.

 

2013-02-08_221458_zpsa5f5964f.png

I got same problem...



Frits
  • Members
  • 6 posts
  • Last active: Aug 20 2014 10:17 PM
  • Joined: 23 Mar 2013

Thanks 

Guest10

 

​Maybe may question was a bit wrong, i don't want to find the second image

I want FindClick to stop after 2 hits, .

 

#SingleInstance Force
#Include, FindClick.ahk
c::
opt = a14, o128
vullen = o100 w4000,500
start:

If % FindClick("Ris_leeg1.png", "o125") = 0 ; finding empty stores
	{
		If % FindClick("Ris_coin.bmp", opt) = 0
			Reload ;for now reload while testing
		Else ; finding a second coin
		{
			Sleep, 400
			If % FindClick("Ris_coin.bmp", opt) = 0
				Reload ;testing
			Else
			{
			Sleep, 300
			GoSub start 
			}
		}
	}
	Else ; supplying empty store
	{
	Send, {LControl Down}
	FindClick("plus.bmp", vullen)
	Send, {LControl Up}
	FindClick("suply.bmp", vullen)
	FindClick("close.bmp", vullen)
	Sleep, 300
	GoSub start ;not sure but this isnt working.....
	}
return
v::
Reload

 

Thats how i am doing it now.

Its a test code and still some errors,

 

	Send, {LControl Down}
	FindClick("plus.bmp", vullen)
	Send, {LControl Up}

 

For this there should be a better option to, which i cant vind

I have found It 

	FindClick("plus.bmp", "k^{Click} o100 w4000,200")


Frits
  • Members
  • 6 posts
  • Last active: Aug 20 2014 10:17 PM
  • Joined: 23 Mar 2013
penguin114
May be there is a issu whit uac, not sure what the correct names are.

​Try to run it all from D:\testdir, or similar, so user or admin rights aren't the promblem

EDIT

I do have the error to,
run as ADMIN still error,
Save in D:\test Still error
I do find a test.png Local/Temp dir
9 out of the 10 times add image search option in dialog will crash the script

No solution

Edited by Frits, 27 March 2013 - 04:13 PM.


berban
  • Members
  • 202 posts
  • Last active: Apr 12 2019 01:08 AM
  • Joined: 30 Dec 2009

Frits – Regarding your question about clicking two images, there are two ways you can do it. If the following criteria are met

  • The image looks different after it is clicked (this way it won't simply find the same image both times)
  • It doesn’t matter which two of the images you click

…then simply calling findclick twice is probably easier and indeed even more CPU-efficient.

Loop 2
   FindClick("Ris_leeg1.png")

The ‘e’ option is useful if you need to get the locations of ALL the instances of the image onscreen. It uses a more complicated method of searching, and for this search to work it’ll need to loop through all instances which is more time-consuming if you only need 2. However if you wanted to use the e option for this task it would look something like this

Results := FindClick("Ris_leeg1.png", "e n")
Loop, Parse, Results, `n
   If A_Index > 2
      Break
   Else
      Click %A_LoopField%

i.e. basically what Guest10 said before


Find me on the new AutoHotkey forums and send me a message if you have a question about any of the scrips I've posted to this forum!


berban
  • Members
  • 202 posts
  • Last active: Apr 12 2019 01:08 AM
  • Joined: 30 Dec 2009

Regarding this error

 

2013-02-08_221458_zpsa5f5964f.png

 

...My apologies to Samfy, I think I simply overlooked this error when he originally posted it over a month ago. I am not sure what is causing this error but it should be easy enough to sort out. All I would like you to do is to try to reproduce the behavior and instead use this copy of findclick http://pastebin.com/vdbkE7Gt - all I did was add one line to capture the offending gui option. Run your script that causes the error, and when the error box pops up the code will be stored in the Clipboard. Close the script and paste the code here.


Find me on the new AutoHotkey forums and send me a message if you have a question about any of the scrips I've posted to this forum!


berban
  • Members
  • 202 posts
  • Last active: Apr 12 2019 01:08 AM
  • Joined: 30 Dec 2009

penguin114
May be there is a issu whit uac, not sure what the correct names are.

​Try to run it all from D:\testdir, or similar, so user or admin rights aren't the promblem

EDIT

I do have the error to,
run as ADMIN still error,
Save in D:\test Still error
I do find a test.png Local/Temp dir
9 out of the 10 times add image search option in dialog will crash the script

No solution

 

I am not sure exactly what code you are referring to that gives you errors here, can you clarify this Frits?


Find me on the new AutoHotkey forums and send me a message if you have a question about any of the scrips I've posted to this forum!


Frits
  • Members
  • 6 posts
  • Last active: Aug 20 2014 10:17 PM
  • Joined: 23 Mar 2013

the same errors as Samfy.
when using findclick()
on a other laptop I could safe the pic. but testing or giving the options would make it crash

 

using http://pastebin.com/vdbkE7Gt the same errors happen



berban
  • Members
  • 202 posts
  • Last active: Apr 12 2019 01:08 AM
  • Joined: 30 Dec 2009

By crashes do you mean it shows the above error? If so then running the code from pastebin.com should put code in your clipboard and I'd like you to paste that here if you could.

 

If you don't mean the error dialog shown above, then what error are you talking about?


Find me on the new AutoHotkey forums and send me a message if you have a question about any of the scrips I've posted to this forum!


penguin114
  • Members
  • 8 posts
  • Last active: Aug 10 2013 11:00 AM
  • Joined: 12 Jan 2013

By crashes do you mean it shows the above error? If so then running the code from pastebin.com should put code in your clipboard and I'd like you to paste that here if you could.

 

If you don't mean the error dialog shown above, then what error are you talking about?

When i try to save the image it says: 98:Show, NA x-100 y-100 w28 h24, ,

and when i try to add option to it says: 98:Add, Button, gFindClickClose xp y+10 w hp,&Help

and freezes



Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

i am using this script extensively in several applications. however, in certain applications, the target image could very by shades of colors, etc. In these cases, I select and save all variations such as image1, image2, image3, ... etc., and then include in the script in the following fashion to cover all possible cases. is there a better (more efficient) way to script this in a more compact manner?

 

...
MyImage := "C:\...\image1.png"
Results := FindClick(MyImage, "n e")
Loop, Parse, Results, `n
If (A_Index = 1) {
StringSplit, Coords, A_LoopField, `,
Break
}
Click, %Coords1%,%Coords2%
}
Sleep, 100
{
MyImage := "C:\...\image2.png"
Results := FindClick(MyImage, "n e")
Loop, Parse, Results, `n
If (A_Index = 1) {
StringSplit, Coords, A_LoopField, `,
Break
}
Click, %Coords1%,%Coords2%
}
Sleep, 100
{
MyImage := "C:\...\image3.png"
Results := FindClick(MyImage, "n e")
Loop, Parse, Results, `n
If (A_Index = 1) {
StringSplit, Coords, A_LoopField, `,
Break
}
Click, %Coords1%,%Coords2%
}
...


berban
  • Members
  • 202 posts
  • Last active: Apr 12 2019 01:08 AM
  • Joined: 30 Dec 2009

Hey Guest10,


There are two things you can do to make your script more compact.

 

  1. It seems you are using the "e" option unnecessarily. If you just want to find the image and then click on it, there is no need to use "e". I.E. this code:
    MyImage := "C:\...\image1.png"
    Results := FindClick(MyImage, "n e")
    Loop, Parse, Results, `n
    If (A_Index = 1) {
    	StringSplit, Coords, A_LoopField, `,
    	Break
    }
    Click, %Coords1%,%Coords2%

    does the exact same thing as this:

    FindClick("C:\...\image1.png")

    So you can compact it a bit there.

     

  2. If you want to search for multiple images, the easiest way to do this is via a parsing loop like this:

    Images = C:\image1.png|C:\image2.png|C:\image3.png
    Loop, Parse, Images, |
    	If FindClick(A_LoopField) ; If the image is found (it will also be clicked on)
    		Break ; Stop searching cause you've already found the image

Find me on the new AutoHotkey forums and send me a message if you have a question about any of the scrips I've posted to this forum!


Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

thanks!!! however, i must use "e" option because there are several instances of the same logo image on the screen (or the possibility thereof). i modified the script accordingly (as follows) and it works great:

Images = C:\...\image1.png,C:\....\image2.png,C:\...\image3.png

Loop, Parse, Images, `,
If (Results := FindClick(A_LoopField, "n e")) ; "n" tells FindClick to not click on the images
Break

Loop, Parse, Results, `n
If (A_Index = 1) {
StringSplit, Coords, A_LoopField, `,
Break
}
Click, %Coords1%, %Coords2%


scythez0r
  • Members
  • 11 posts
  • Last active:
  • Joined: 09 Mar 2013

Sorry if this is a dumb question, but can you right click? And can I set a mouse speed?



berban
  • Members
  • 202 posts
  • Last active: Apr 12 2019 01:08 AM
  • Joined: 30 Dec 2009

Right click can be done using the "k" option (for what "keystroke" to send when the image is found)

FindClick("image", "k{RButton}")

Since right click is the default option, you need only put k.

FindClick("image", "k")

In terms of mouse speed, do you mean that you want the mouse to travel at a certain speed to and from the image? If that's the case I actually had never considered needing that but it could be added to the script easily enough.


Find me on the new AutoHotkey forums and send me a message if you have a question about any of the scrips I've posted to this forum!