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

Post your working scripts, libraries and tools
User avatar
berban
Posts: 61
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: 1118
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: 61
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: 61
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: 10
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: 10
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: 61
Joined: 14 Apr 2014, 03:20

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

17 Jun 2018, 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.
daffy82
Posts: 10
Joined: 03 Aug 2016, 00:42

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

Today, 00:38

berban wrote: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.



Hi berban.

Thanks for your reply and thanks for making this script. Its very nice and I love it!

1. ok
2. I will and post update if I find anything
3. Yes thats exactly what I need. Script looks for a text box (Company) and then moves 300px to the right and then clicks a dropdown arrorw - gif: https://i.imgur.com/3NQYB5B.gifv (this part works if I run it by itself)
4. The screen does change when the script clicks the first time... It clicks on an outlook ribbon. I made a gif so you can see what i mean: https://i.imgur.com/zISpdZP.gifv

Edit: result of the debugger https://justpaste.it/69e9a

Edit 2: I have 3 monitors so the debugger shows 3 Searches. When I click on a search the screen turns red. When the screen is red I click the ribbon manually and the popup menu is not red. I dunno if thats a problem? A gif showing this: https://i.imgur.com/hfmheYS.gifv
User avatar
berban
Posts: 61
Joined: 14 Apr 2014, 03:20

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

Today, 03:45

Thanks for the helpful gifs! So I'm still not completely sure why it wouldn't work but my suggestion would be that for the ribbon one, I generally use the alt keys for those. For instance, in Microsoft Word, if I want to access the ribbon I just press Alt and the accelerator keys show up in little black tooltips:

Press "alt":
Image
Press "h" for home tab:
Image
Press "ff" for font (font face, I assume)

So if I want to change the font to Arial, it'd be something along the lines of

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

Send !hffArial{enter}

This is incredibly reliable in office apps. You can probably do something similar for the outlook one. Maybe alt+h+a to get to the archive button, then {down} or {down 2] to go to the correct option and then {enter} to select it.

Also by the way the red shading thing isn't a problem, when you click the archive button it creates a new menu window which goes over the red window from AutoHotkey.

Similarly, for the dropdown one I'd try using Send to press {tab} a bunch of times until you get focus to the right input, then send {down} to make the dropdown menu appear. It might be more reliable. Either that or use findclick to search for the little black dropdown arrow instead - in this case, the one you want is the top one so it'll be the one that gets clicked.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 14 guests