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

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

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

05 May 2018, 00:53

Hm...
AutoHotkey.chm wrote:ErrorLevel is set to 0 if the image was found in the specified region, 1 if it was not found, or 2 if there was a problem that prevented the command from conducting the search (such as failure to open the image file or a badly formatted option).

Have you used imagesearch in the past without issues? What if you create a png file with paint.exe, do you still get ErrorLevel 2?
fenchai
Posts: 175
Joined: 28 Mar 2016, 07:57

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

05 May 2018, 12:45

berban wrote:Hm...
AutoHotkey.chm wrote:ErrorLevel is set to 0 if the image was found in the specified region, 1 if it was not found, or 2 if there was a problem that prevented the command from conducting the search (such as failure to open the image file or a badly formatted option).

Have you used imagesearch in the past without issues? What if you create a png file with paint.exe, do you still get ErrorLevel 2?


OK so I tested on my main computer and it worked, then I changed the image and it does not find now. So far it is pretty hit and miss. I tested with the usual imagesearch function and it works so i don't know what the problem is. Let's just say I gave up on fixing this ¯\_(ツ)_/¯ But your script really is good. It's a shame it is pretty hit or miss for me.
User avatar
Xtra
Posts: 1114
Joined: 02 Oct 2015, 12:15

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

05 May 2018, 14:05

If you are using the path: \AppData\Local\Temp\ and getting errorlevel 2 when image searching the file simply doesnt exist you will need to run the findclick script as admin when creating the image.

Personally i wouldnt use that path try saving the images at the script level or in a sub-folder.

HTH
User avatar
berban
Posts: 60
Joined: 14 Apr 2014, 03:20

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

07 May 2018, 08:48

Yes Xtra is absolutely correct. If for some reason you don’t have privileges for %A_Temp%, or if you’d simply prefer to use another directory, you can change this line in the code:

Code: [Select all] [Download] GeSHi © Codebox Plus

TempFile = %A_Temp%\%A_ThisFunc%Temp.png ; Directory where a temporary imagefile will be created (ImageSearch only accepts an imagefile as input)


That being said, if you can see the blurry image preview from inside the debugger, that means the AutoHotkey GUI is able to load the image from %A_Temp% so I doubt permissions are the issue.

If it is indeed an issue with FindClick, my best guess would be that there's something up with the GDI+ code that is causing it to create a corrupted .PNG file that AutoHotkey is able to read for the preview but not for ImageSearch. Just a guess though.
dice4321
Posts: 6
Joined: 21 May 2016, 21:44
Google: Fatal_Pulse

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

28 May 2018, 19:16

The function has worked like magic so far thanks berban!

I have a question tho. I have the r option on, but for the function to work, it seems to be, the window always has to be on top else the function wont find the image, is there a way to find the image in a window behind other windows?
User avatar
berban
Posts: 60
Joined: 14 Apr 2014, 03:20

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

29 May 2018, 14:08

Hi dice4321,

So the way AutoHotkey's ImageSearch command works, it basically scans the visible screen area for the image, which is essentially the same area that you can see with your two eyes. If the image is hidden behind another window and you can't physically see it, then this won't work. You'd need to use another method.

If, on the other hand, you just mean the window is not the ACTIVE window but still visible somewhere on the screen, then you can definitely use FindClick. You can either just search the entire screen (remove "r") or you can search ONLY the borders of that other window by defining it with the r option.

Code: [Select all] [Download] GeSHi © Codebox Plus

FindClick("image.png", "r""My window title""") ; searches relative to the window with the title "My Window Title", based on your TitleMatchMode settings
FindClick("image.png", "r" WinExist("My Window Title")) ; you can also use a HWND via WinExist. I prefer this way because you don't have to escape the quotation marks
FindClick("image.png", "r" WinExist("My Window Title") " mControlClick") ; use sendmode = controlclick to avoid activating that other window when a click is sent
daffy82
Posts: 9
Joined: 03 Aug 2016, 00:42

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

14 Jun 2018, 07:21

Is it possible to find an image on screen and the click on that image but in the far right side of the picture? (I want the script to click the little arrow: https://i.imgur.com/duhGhZC.png to activate the dropdownmenu

Found the solution (offset)
daffy82
Posts: 9
Joined: 03 Aug 2016, 00:42

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

15 Jun 2018, 01:09

Question:

Why does my script only find the very first image? It does not click on 2nd or 3rd img:

Code: [Select all] [Download] GeSHi © Codebox Plus

#Include C:\Scripts\AHK\berbar_image_search.ahk
!t::
FindClick()
!k::
FindClick("ribbon", "k{Click}")
sleep 2000
FindClick("2archive", "Center1 k{Click}")
sleep 2000
FindClick("NewFile", "x300 k{Click}")
return
User avatar
berban
Posts: 60
Joined: 14 Apr 2014, 03:20

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

Yesterday, 10:38

Hi daffy82, sorry but I can't tell you based on what you've posted. Nothing in that code would prevent it from working correctly.

A few comments I could give you:
  1. k{click} and Center1 are not needed. The default behavior is to click at the center of the image.
  2. Try using the dx option to help diagnose what is wrong. FindClick("2archive", "dx") Run it and scroll through the items in the GUI to see if anything looks suspicious
  3. x300 means it'll click 300 pixels to the right of the image. Is that what you intended?
  4. It's possible that the first click changes the look of things onscreen - for instance, when you click on a menu it might cover up another part of the screen. Make sure that isn't happening here by making sure you take the screenshot images when the screen looks how it'll look while the script is running.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 8 guests