FindClick() - ImageSearch, Clicking, & More [Newest Version]

Post your working scripts, libraries and tools
User avatar
berban
Posts: 71
Joined: 14 Apr 2014, 03:20

FindClick() - ImageSearch, Clicking, & More [Newest Version]

Post by berban » 06 Jun 2016, 20:52

Updated February 17, 2017 (fixed bug with e/d/w options found by Vizzy)
Updated July 23, 2016 (per suggestions of Remonell)
Updated July 20, 2016 (fixed GDI+ image creation problem)
Updated June 6, 2016 (fixed 1-pixel offset with "a" option, tweaked debugger)


Note: This is not a new function but the old post got archived meaning no one can reply, so now you can reply here if you need help.

A script that combines many uses of the AutoHotkey ImageSearch command into one powerful and easy-to-use function.

GitHub: https://github.com/berban/FindClick
Script: https://github.com/berban/FindClick/blo ... dClick.ahk
Documentation: https://github.com/berban/FindClick/blo ... dClick.pdf


FindClick is standard library compatible and works with AutoHotkey Basic or _L

Some of this function's uses in no particular order:
  • Click on an image (find on-screen image, find picture, imagesearch, click on picture)
  • Click on a color (find color, search for color, PixelSearch replacement, pixelsearch windows 7, pixelsearch windows 8)
  • Search all monitors for an image (imagesearch multi-monitor support)
  • Find all instances of an image (count images, imagesearch multiple image)
  • Create an image for ImageSearch (imagesearch help, imagesearch macro, imagesearch library, simple imagesearch script, easy imagesearch)
(This list is mostly for forum search keywords, since the documentation is in a separate file and won't be searched.)

Image of the screenshot creator gui:
Image

Image of the debugger gui:
Image

Image of the function in my standard library:
Image

(Sure it's huge but it has lots of features! And it fits nicely into your library if you set SciTE to condense labels like I do.)


I apologize, the documentation trails off in a few parts, I never got around to finishing it. But just ask here if you have any questions! :)
Last edited by berban on 05 May 2017, 23:21, edited 5 times in total.
guest3456
Posts: 2419
Joined: 09 Oct 2013, 10:31

Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]

Post by guest3456 » 10 Jun 2016, 11:51

that image creator may be very useful, good work

carno
Posts: 128
Joined: 20 Jun 2014, 16:48

Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]

Post by carno » 11 Jun 2016, 12:47

Thanks for the update!
Guest

Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]

Post by Guest » 16 Jul 2016, 00:25

Hey berban,

awesome work you did there! Unluckily I am still getting the GDI+ error.

http://prntscr.com/btj2xc

Do I have to download and install the GDI+ module somewhere first? I hoped it was somehow included in windows.

Windows 10 x64
AHK v1.1.22.03 (no idea if unicode or L etc...if you tell me how to find that out I will do it)


The code i executed:
!t::
FindClick()
return

Apprecciate your help!
User avatar
Xeo786
Posts: 189
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]

Post by Xeo786 » 16 Jul 2016, 06:12

Great work.. man :)

I also tried "FindClick()" facing same msg, Issue is in line number 915

Code: Select all

If !FileExist(Param1 "." Param2)  ; line915  
here Param1 := 1 , Param2 is location , Param3 := PNG , 3 and 4 are x and y axis and reamining are colors :) pixel ...

then I have also tried

Code: Select all

If !FileExist(Param2 "." Param3)  ; in line915  
still have same issue :( I am just trying to figure out :) hoping @Berban resolved this
"When there is no gravity, there is absolute vacuum" -Game changer theory
Remonell
Posts: 5
Joined: 15 Jul 2016, 19:53

Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]

Post by Remonell » 16 Jul 2016, 07:31

I got the very same issue.
User avatar
SnowFlake
Posts: 368
Joined: 28 Apr 2015, 05:41
Google: floowsnaake
GitHub: floowsnaake
Contact:

Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]

Post by SnowFlake » 16 Jul 2016, 13:17

Have the problem been fixed yet?
:yawn:
User avatar
berban
Posts: 71
Joined: 14 Apr 2014, 03:20

Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]

Post by berban » 20 Jul 2016, 22:22

All set! After an hour of poring over the code I finally found the one typo that was causing all the issues. Too bad it wasn't anything more fun. Thanks for being patient!
Remonell
Posts: 5
Joined: 15 Jul 2016, 19:53

Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]

Post by Remonell » 23 Jul 2016, 14:28

berban wrote:All set! After an hour of poring over the code I finally found the one typo that was causing all the issues. Too bad it wasn't anything more fun. Thanks for being patient!
Thank you very much for fixing it so fast! Will try it out and reply if there is something else not working properly!

Edit: When I create a png with your tool, and right after that click on 'Test', I assume that it searches for that just created png anywhere on my 2 monitors. Unluckily it does not find it in the test, although it does find it with my script and my ImageSearch function. And the image that is to be found is open on my main desktop in an open window. Here is a screenshot of your tool after the testing:

http://prntscr.com/bwmx9f

Edit2: When I am in the FindClick Debugger and I click on Settings -> Edit Debugger Settings it gives me a error message:

http://prntscr.com/bwn0kb


Also is there a way to go back into the image creating menu when you are in the FindClick Debugger window?

Another thought, it would be great if the image creator tool would take the path you chose the last time as the default path. I assume though, that this possibility would only be possible with an extra config file. And I could totally understand if you don't want that. If you do though, there is another option I personally would apprecciate that could be realized with an extra config file. It would be great, if the 'FindClick Screenshot Creater' wouldn't always open in the middle of my main screen. Would be cool if your tool would save the last position of the window and reopens it there the next time. Cause right now I open it and always have to move it aside.
User avatar
berban
Posts: 71
Joined: 14 Apr 2014, 03:20

Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]

Post by berban » 23 Jul 2016, 18:40

Hey Remonell! I made a minor update to address some of your issues.
Remonell wrote:When I create a png with your tool, and right after that click on 'Test', I assume that it searches for that just created png anywhere on my 2 monitors. Unluckily it does not find it in the test, although it does find it with my script and my ImageSearch function. And the image that is to be found is open on my main desktop in an open window.
You are indeed right, the script will search on both your monitors for the image. In your screenshot you'll see it says "Search #1" ... "Search #2": those indicate search on your first monitor and then the second. (When you click on those entries the monitor it searches will be shaded red.) I don't have a ready explanation for why it didn't find the image, although one common issue is that the image is a button or something that changes appearance when your mouse hovers over it. Since the capture rectangle follows the mouse, you may have captured it in this state and when you click on "Test" you are no longer hovering over it and its appearance has changed. To work around this issue, make sure the "Allow Offset" box is checked in the image creator gui. Then pause the updater by pressing the backtick (`) key, move the mouse a little, and unpause it. This allows you to capture an image that isn't directly under the mouse.

One thing you can do inside the debugger window to check what image is being searched for is to click on the step "Measuring width and height". This will display a preview of the image so you can see what it looks like. (Edit: I actually just changed the name to make this more self explanatory.)
Remonell wrote:When I am in the FindClick Debugger and I click on Settings -> Edit Debugger Settings it gives me a error message.
What you have to do here is to put in the path to your editor on your computer. Open up the script and search for "EditorPath" (it's on line 952 in the updated version). Put in the path to the .exe of your desired editor (I use Notepad++) here. On the next line, it says "EditorCommand = ". Here is where you put the format of your editor that will open the script to the right line. This varies by editor. Unfortunately windows notepad is unable to do this so you need an editor like Notepad++ or SciTE for this to work. `%LineNumber`% indicates where the line number should go. (Edit: I also changed this to make it more explanatory)
Remonell wrote:Also is there a way to go back into the image creating menu when you are in the FindClick Debugger window?
If you close the debugger window (or press esc) it will return to the image creating window. But no unfortunately you can't switch back and forth between them if that's what you mean.
Remonell wrote:Another thought, it would be great if the image creator tool would take the path you chose the last time as the default path.
You're right I didn't want to have any config files, but you can set some "favorite folders" by changing the variable "DefaultDirs" located on line 12 of the script. These folders will populate the dropdown list in the image creator save box, and you can quickly jump through them by pressing up and down. An added bonus is that you can also search for any images in the "DefaultDirs" without putting the full path. For instance, if "image1.png" is located in one of those folders you only need to say FindClick("image1.png"), or FindClick("image1") because png/bmp is assumed.
Remonell wrote:It would be great, if the 'FindClick Screenshot Creater' wouldn't always open in the middle of my main screen.
I just added a setting you can change inside the script settings. Go to the image creator settings and on line 1277 of the code you can edit GuiX = and GuiY = . Put in some number to have the gui first appear at these coordinates.

Let me know if you have any issues with any of that.
User avatar
Chunjee
Posts: 53
Joined: 18 Apr 2014, 19:05
GitHub: Chunjee

Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]

Post by Chunjee » 15 Aug 2016, 17:23

This has incredible polish and It made one of my latest projects a breeze. Thank you.


However.... I find myself doing dumb stuff like this:

Code: Select all

While(FoundSelector != 1) {
	FoundSelector := FindClick(A_ScriptDir . " \Data\Resume.png", "Silent Count 80")
	sleep, 100
}



If someone has more free time than I; something like this would be cool:

Code: Select all

;Create new Object
ScannerObj := New Findv3("Silent 40") ;Silient should honestly just be assumed

;Find and click
ScannerObj.click(A_ScriptDir . "\assets\filename.png")


;Return True or False
Return_bool := ScannerObj.test(A_ScriptDir . "\assets\filename.png")
If (Return_bool) {

}
;Or more direct
If (ScannerObj.test(A_ScriptDir . "\assets\filename.png")) {
	;Ok How many?
	CountVar := ScannerObj.count(A_ScriptDir . "\assets\filename.png")
}


;change a setting
ScannerObj.setting_sendMode("send")
User avatar
berban
Posts: 71
Joined: 14 Apr 2014, 03:20

Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]

Post by berban » 15 Aug 2016, 18:49

Hey Chunjee,

Thanks for the kind words! To be honest, I've hardly done any work with AutoHotkey objects and I don't really use AutoHotkey or code in general too much anymore so I don't think I'll be making a major change like that anytime soon (but if someone else wants to tackle it be my guest.) But I'm not even really sure how helpful making an object would be. I mean you could create an object and associate the search options with it, but that's about all the information the object would contain. And it's not like imagesearch keeps a handle to the image file open or anything, so I can't see how performance could be improved. Maybe if you were using something like gdip_imagesearch() then there would be more optimization you could do using objects, but as far as I can tell, all that this would do for you would be to save you from inputting the options again.

And yeah I see how it might be more intuitive if you had methods and properties (image.count, image.test, image.click()) but each of those calls would essentially do the same thing (i.e. run an AutoHotkey imagesearch) and only the action taken after would differ. So to me this is slightly deceptive and I think it is better for the user to see the options as slight variations on the same action. For instance, in your example:
Chunjee wrote:

Code: Select all

If (ScannerObj.test(A_ScriptDir . "\assets\filename.png")) {                ; to "test", an imagesearch must be performed
    CountVar := ScannerObj.count(A_ScriptDir . "\assets\filename.png")      ; to "count", an imagesearch must be performed. Much more performance-efficient to count and test at the same time.
                                                                            ; If the count number is 0, using "count" does not take any longer so there is no penalty.
}
I hope that makes sense. Or maybe I just don't fully understand what you mean.

By the way, in your example here:

Code: Select all

While(FoundSelector != 1) {
	FoundSelector := FindClick(A_ScriptDir . " \Data\Resume.png", "Silent Count 80")
	sleep, 100
}
... you can use the "w" (wait) option if you just want to wait for one image.

Code: Select all

FindClick(A_ScriptDir . " \Data\Resume.png", "Silent w") ; will wait indefinitely. Sleep of 100 is already the default but you can change that with the w option
The only reason I would use "count" there is if you are waiting for a certain number (more than one) of images to come up. If that's the case, keep doing what you're doing. Otherwise I wouldn't use "Count".

Also "80" is meaningless here - if you want 80 shades of variation you need "o80" ("o" for "imagesearch options", from the help manual)

Chunjee wrote:Findv3("Silent 40") ;Silient should honestly just be assumed
I'm surprised if you are getting error boxes - I never get these - but if you would like to make it default you can change this on line 49 and put Silent := True:

Code: Select all

, Silent := True,        Silent_user := False       ; No Dialogs
User avatar
Chunjee
Posts: 53
Joined: 18 Apr 2014, 19:05
GitHub: Chunjee

Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]

Post by Chunjee » 15 Aug 2016, 19:12

I will say that it is probably more approachable as a function. The functionality I was talking has to do more with utility and perhaps my personal style than anything. Probably I just hate repeating the options over and over. Your tip on editing silent mode will help I bet.


There are a few flaws in my examples. Apparently I have been using the variation option wrong all along :facepalm:
dice4321
Posts: 6
Joined: 21 May 2016, 21:44
Google: Fatal_Pulse

Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]

Post by dice4321 » 17 Dec 2016, 03:21

Is it possible to find the image, and have the function click a random spot on the image?
User avatar
berban
Posts: 71
Joined: 14 Apr 2014, 03:20

Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]

Post by berban » 18 Dec 2016, 05:49

Absolutely. Say your image is 21 pixels wide and 11 pixels tall. Here would be an example in that case:

Code: Select all

Random, RandX, -10, 10 ; the default place to click is in the center of the image. so -10 would offset 10 pixels to the left of the center and +10 would offset 10 pixels to the right of the center
Random, RandY, -5, 5 ; same for the y offset
FindClick("myimage", "x" RandX " y" RandY) ; if the image is found then it will be clicked with the random offsets specified.
If that's not what you're looking for you could try the "Func" option. An example of that is given here. In that case it is using random speed but random location wouldn't be much different.

(Side note: If your image is has even dimensions then the center is taken closer to the top left corner. E.g. if it is 4x4 there is no true "central" pixel so the center is taken as the second from the top and the second from the left).
carno
Posts: 128
Joined: 20 Jun 2014, 16:48

Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]

Post by carno » 22 Dec 2016, 16:51

What is the advantage or some applications of clicking a random spot on the image rather than the default center of the image?
User avatar
berban
Posts: 71
Joined: 14 Apr 2014, 03:20

Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]

Post by berban » 22 Dec 2016, 17:52

Probably to circumvent the anti-cheat in his/her game
User avatar
Darth_Diggler
Posts: 13
Joined: 21 Dec 2016, 10:07

Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]

Post by Darth_Diggler » 07 Jan 2017, 03:51

Thanks berban for a great function.
I already use findclick to make and crop screenshots but Is there a way to edit pixel colours of a screenshot or could this be added to findclick. It would be a very handy feature as I regularly make screenshots of text that has a semi transparent background which ends up being lots of different colours in the screenshot.
I normally edit in photoshop and make background all black or white so I can use the transblack or transwhite function. So it would be very handy if could edit the screenshot background colour in findclick instead of photoshop.
User avatar
berban
Posts: 71
Joined: 14 Apr 2014, 03:20

Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]

Post by berban » 09 Jan 2017, 16:26

Hey Darth_Diggler, I originally wanted to add something like that to the script but never got around to it. It would also have been pretty involved. So I guess the short answer is no I don't have that feature and am not planning on adding it unfortunately, sorry.
Also personally I use mspaint for editing screen clips if I need to, that works fine, although I don't have photoshop so maybe that is better.
Vizzy

Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]

Post by Vizzy » 12 Feb 2017, 14:30

Hi Berban,

Thank you so much for this excellent script, it's saved me heaps of time as well as looking after my wrists!

I am having a bit of difficulty with the 'Wait until image is found' option however. It seems to be ignoring the total time to wait and endlessly looping until the image is found.

For instance if I added the option w500,50 I was under the impression that would wait 500ms total, checking every 50ms for a total of 10 checks. However when I add this and run in diagnostic mode I get this:

http://imgur.com/6KS1kke



Thanks for any help!
Post Reply

Return to “Scripts and Functions”