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

Post your working scripts, libraries and tools for AHK v1.1 and older
zuff

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

20 Dec 2017, 14:05

tackis wrote:i was wondering if it is possible to search for 5+ images and if none are present click another (a skip button), then search for the 5+ images and so on
my programming skills are minimal
I too would like to know if this is possible.

The only way I can imagine doing it would be to have a loop that goes through multiple FindClick and somehow breakout of it when it finds one or a certain amount of time has passed (like increasing a variable by +1 everytime a failed check has gone through)
User avatar
berban
Posts: 97
Joined: 14 Apr 2014, 03:20

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

02 Jan 2018, 18:30

Hi guys,

Sorry for the delayed response. Yes you are right that this is not a built-in feature of the function. You'd have to loop it.

Code: Select all

ImageList := ["image1.png", "image2.png", "image3.png"]

For key, ImageFile in ImageList
{
	If FindClick(ImageFile, Options) ; fill in the options
	{
		Break
	}
	; Do other stuff each loop, like maybe add a sleep
}
User avatar
berban
Posts: 97
Joined: 14 Apr 2014, 03:20

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

05 Mar 2018, 16:46

You’re in luck, there’s a “quick start guide” in the documentation
https://github.com/berban/FindClick/blo ... dClick.pdf
Check out page 4
Bambuzo

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

14 Mar 2018, 13:31

This doesn't seem to work for me

When I use the debux options "dx", I get the following error: https://i.imgur.com/Sc1VQt4.png
User avatar
berban
Posts: 97
Joined: 14 Apr 2014, 03:20

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

14 Mar 2018, 15:33

My guess is that you changed the escape character? Via #EscapeChar

If that's the case then find where it says

Code: Select all

PauseHotkey = ``
Also

Code: Select all

HotkeyCompactView = ``
... And change `` to `

Or change it to

Code: Select all

PauseHotkey:= "`"
Or just change the hotkey
alesyt0h
Posts: 214
Joined: 28 Jan 2015, 20:37

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

02 May 2018, 03:53

Hey!

Can I accomplish witth this script to search for an image repeated on the screen but without the imagefile not stored on my disk/url nor gdi haystack neither? It's for a site which the images are never the same but at least two are repeated
User avatar
berban
Posts: 97
Joined: 14 Apr 2014, 03:20

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

02 May 2018, 08:54

Hi alesyt0h!

Sure you could do that with a few pretty simple extra steps. You can first create the image with GDI+ then use FindClick with that image once you have it. It would look something like this:

Code: Select all

; The image you are looking for will be initially found at (100, 200) relative to the screen and be 10x10 pixels
ImageX = 100
ImageY = 200
ImageW = 10
ImageH = 10

TempFile := A_Temp "\Temporary_Image.png"
Gdip_Screenshot(TempFile, ImageX, ImageY, ImageW, ImageH)
FindClick(TempFile)
Return

;============================================ Functions =============================================

Gdip_Screenshot(OutputPath="", x="", y="", w="", h="") ; Just a simplified function for taking a screenshot using GDI+
{
	If (OutputPath = "")
		OutputPath := A_Desktop "\" A_Now ".png"
	If (x = "")
		x := 0, y := 0, w := A_ScreenWidth, h := A_ScreenHeight
	IfWinExist, ahk_id %x%
		WinGetPos, x, y, w, h, ahk_id %x%
	FileDelete, %OutputPath%
	pToken := Gdip_Startup()
	pBitmap := Gdip_BitmapFromScreen(x "|" y "|" w "|" h)
	Gdip_SaveBitmapToFile(pBitmap, OutputPath)
	Gdip_DisposeImage(pBitmap)
	Gdip_Shutdown(pToken)
	Return OutputPath
}

#Include, Gdip.ahk ; get it at https://github.com/berban/Gdip/blob/master/Gdip.ahk
#Include, FindClick.ahk
I couldn't find a copy of the version of Gdip.ahk that I use online, so I uploaded it to my Github: https://github.com/berban/Gdip/blob/master/Gdip.ahk

My question, though, is how are you going to be able to find the image the first time in order to take the screenshot? i.e. how will you know the values of ImageX, ImageY, etc in the code above?
alesyt0h
Posts: 214
Joined: 28 Jan 2015, 20:37

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

03 May 2018, 04:14

Thank you!! Maybe i can accomplish what i want with that code!!
berban wrote:My question, though, is how are you going to be able to find the image the first time in order to take the screenshot? i.e. how will you know the values of ImageX, ImageY, etc in the code above?
Lucky for me, the "random" images are always at the same coordinates.

Still It doesnt match them, I'm using the parameters "e Count" to tell me how many instances of the ñicture are found on the screen.

The thing is, the "repeated" image is rotated(random degree), while the normal one is not, how i can make finclick found the rotated one? Tried with o100 and didn't work either :(

Thanks!
User avatar
berban
Posts: 97
Joined: 14 Apr 2014, 03:20

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

03 May 2018, 09:06

Oh... :| that throws a big wrench into the works unfortunately. You can use Gdip to rotate images, although I haven't done this personally so I wouldn't be able to tell you how. Also I'd be worried that the rotation wouldn't result in the exact same image that you see on screen. When you perform a complex transformation on an image such as resizing or rotation that isn't 90°, there's a lot of interpolation and while the result may look visually the same, the pixels may not be exactly the same which is what you need for something like imagesearch.

Is there at least a unique color in the image that wouldn't be present somewhere else on the screen? For instance, if the image is a basketball that is rotated, you may still be able to find it regardless of rotation if there is no other similar shade of orange somewhere on the screen. I'd say that would be your best bet.
alesyt0h
Posts: 214
Joined: 28 Jan 2015, 20:37

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

04 May 2018, 13:01

Damn :/ ... sadly there is no unique color in the image, it's the huge variation among all the images and I will have to take examples of a color one by one of like 2000 images.

I'd thought about what you said to rotate images with Gdip and save 360 images and search one by one on the screen, the interpolation is true but It won't work even with o100 parameter? iirc autohotkey allows up to 255 shades of variation with *n command. It may work?
User avatar
berban
Posts: 97
Joined: 14 Apr 2014, 03:20

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

04 May 2018, 20:00

You're welcome to try it, but personally I doubt it will work. You definitely can go up to 255 but before long you'll be matching everything on the screen.
I think people tend to overestimate the usefulness of the "shades of variation" parameter - it's a very simple mathematical operation. By comparison, any manipulation of an image done while rendering a game or website or other application is often much more complex and just changing the shades won't match it.
fenchai
Posts: 290
Joined: 28 Mar 2016, 07:57

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

04 May 2018, 20:59

why is this happening, I can't even click on anything because image not found. Am I missing something? https://i.imgur.com/etTkVNO.gifv
User avatar
berban
Posts: 97
Joined: 14 Apr 2014, 03:20

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

04 May 2018, 22:39

Yeah it's because when you hover over the icon it gets blue because the mouse is over it. When you click "Test" the mouse is no longer over it so it looks different.

To avoid this, check the box "Allow offset", then pause the update, move the mouse, and unpause it. This will allow you to move the selection box to an area away from the mouse.
fenchai
Posts: 290
Joined: 28 Mar 2016, 07:57

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

04 May 2018, 22:52

berban wrote:Yeah it's because when you hover over the icon it gets blue because the mouse is over it. When you click "Test" the mouse is no longer over it so it looks different.

To avoid this, check the box "Allow offset", then pause the update, move the mouse, and unpause it. This will allow you to move the selection box to an area away from the mouse.
It still doesn't work :/ https://i.imgur.com/g0j3D4u.gifv

btw is there a way to increase the box size?
User avatar
berban
Posts: 97
Joined: 14 Apr 2014, 03:20

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

04 May 2018, 23:00

Really? And the image that pops up under the "image preview" step looks like the area inside the box?

You can make the box bigger if you want, but as far as using ImageSearch in general goes I would highly recommend going no larger than about 10x10. The larger an image you have, the more chances there are for a pixel to not match. I talk about it in more detail in the "ImageSearch suggestions" part of the documentation.

To change the size of the magnifier, change these variables (they're around line 1260 in the code):

Code: Select all

SquareSize = 19                          ; Width and height of each magnifier color square, in pixels
SquaresWide = 22                         ; Width in color squares of the magnifier. Also signifies the width of the region to be magnified, in pixels
SquaresHigh = 18                         ; Same as above for height
SquareSpacing = 2                        ; Spacing between the color squares, in pixels
fenchai
Posts: 290
Joined: 28 Mar 2016, 07:57

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

04 May 2018, 23:06

ok, Then I will stick with the default box size.

Yeah, it's the same pixelated icon. I don't know why it keeps saying image not found. :/
User avatar
berban
Posts: 97
Joined: 14 Apr 2014, 03:20

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

04 May 2018, 23:15

Can you try some other image in another window? like maybe the solid white background of notepad.exe?

If all else fails, look at the step where it says "performing imagesearch". In the text box it should show the actual code used, something along the lines of

Code: Select all

ImageSearch, FoundX, FoundY, 0, 0, 1919 + 0, 1079 + 0, C:\Users\berban\AppData\Local\Temp\FindClickTemp.png
Try putting that into a blank script file with

Code: Select all

Coordmode, Pixel, Screen
<copied imagesearch line>
MsgBox, % ErrorLevel
fenchai
Posts: 290
Joined: 28 Mar 2016, 07:57

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

04 May 2018, 23:27

I tested this time with chrome.

https://i.imgur.com/HAjh40Y.gifv

gives errorlevel 2

Just tested on Another computer, It works, is my PC broken or something>? it's also windows 10 and even has better specs. Wut
Last edited by fenchai on 05 May 2018, 12:24, edited 1 time in total.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 71 guests