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?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).
FindClick() - ImageSearch, Clicking, & More [Newest Version]
Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]
Hm...
Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]
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.berban wrote:Hm...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?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).
Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]
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
Personally i wouldnt use that path try saving the images at the script level or in a sub-folder.
HTH
Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]
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:
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.
Code: Select all
TempFile = %A_Temp%\%A_ThisFunc%Temp.png ; Directory where a temporary imagefile will be created (ImageSearch only accepts an imagefile as input)
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.
Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]
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?
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?
Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]
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.
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
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
Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]
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)
Found the solution (offset)
Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]
Question:
Why does my script only find the very first image? It does not click on 2nd or 3rd img:
Why does my script only find the very first image? It does not click on 2nd or 3rd img:
Code: Select all
#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
Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]
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:
A few comments I could give you:
- k{click} and Center1 are not needed. The default behavior is to click at the center of the image.
- 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
- x300 means it'll click 300 pixels to the right of the image. Is that what you intended?
- 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.
Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]
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:
- k{click} and Center1 are not needed. The default behavior is to click at the center of the image.
- 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
- x300 means it'll click 300 pixels to the right of the image. Is that what you intended?
- 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
Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]
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":
Press "h" for home tab:
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
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.
Press "alt":
Press "h" for home tab:
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
Send !hffArial{enter}
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.
Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]
berban wrote: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":
Press "h" for home tab:
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 ofThis 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.Code: Select all
Send !hffArial{enter}
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.
After you wrote I changed the script to TAB to enter the dialog box from the ribbon menu (genius idea btw ) and I took some new pictures with FindClick and now the script finds the images! Hurray! Thanks alot!
Now I have another question (sorry)...
See this gif: https://i.imgur.com/WhMuhAF.gifv
As you can see the dropdown arrow turns blue'ish when i hover the mouse pointer over it. But the script points to the dropdown arrow SO fast that the dropdown arrow dos'nt get activated. I can see the mouse pointer is the right place but its too fast for the dropdown menu... Funny thing is that it works ca. 1/10 times.
I tried with
Code: Select all
Sendmode Input
Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]
Hm interesting, well you could try a few things like adding "stay" so it doesn’t move away, or "n2" for doing a double click. But maybe the way you were originally doing it is more reliable. If it is clicking in the right spot and the window isn’t responding correctly that’s probably not the best way to approach it
Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]
Nice! With "stay1" and this:berban wrote:Hm interesting, well you could try a few things like adding "stay" so it doesn’t move away, or "n2" for doing a double click. But maybe the way you were originally doing it is more reliable. If it is clicking in the right spot and the window isn’t responding correctly that’s probably not the best way to approach it
Code: Select all
MouseMove, 5, 5, 50, R
Now I believe I can make the whole script! Thanks!
EDIT: Now my script is complete. I have 3 monitors and this script does not give a damn where the dialog box is - it just works! Thanks to Berbans FindClick script. Man this will stay in my toolbox for life!
Again thanks alot!
Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]
Glad it works. Wish I had room for 3 monitors haha. Happy scripting!
Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]
I am using FindClick in the code below to double click on an Image. Is there a better option to put this in one line? I tried FindClick(Image, "e 2"), FindClick(Image, "2 e"), FindClick(Image, 2,"e"), etc., but none worked!
I posted this here also but was of no help: https://autohotkey.com//boards/viewtopi ... =5&t=52965
Code: Select all
Image := "C:\Documents and Settings\User\My Documents\Someimage.png"
FindClick(Image, "e")
Sleep, 100
FindClick(Image, "e")
Return
Last edited by carno on 04 Aug 2018, 15:03, edited 3 times in total.
Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]
Hi carno, sorry for the delay. You are right there is a simple way - use the "n" option.
If you want to vary the amount of time between clicks, you can change that with the "Sleep" option.
(By the way, "e" means click on all instances. If this is intentional that's fine, but if you only expect to ever find one you might want to take it out because it slows the script down a bit.)
Use it like this:FindClick documentation, page 9 wrote:n – Number of clicks
What to give: any integer
Description: The number of times to click on each image.
Code: Select all
FindClick(Image, "e n2")
Code: Select all
FindClick(Image, "e n2 Sleep100") ; will sleep exactly 100 milliseconds like in your code
Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]
Hi, berban, thanks very much! I use your work in several of my apps and they all work great. I read your FindClick Documentation and it mentions option "n" but I was trying 2 (number of clicks) incorrectly like this: .
Code: Select all
FindClick(Image, "e 2")
Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]
Yeah it’s
(Maybe you know that already but just wanted to repeat it in case.)
Let me know if you have any other questions!
Code: Select all
FindClick(Image, "e n2")
Let me know if you have any other questions!
Re: FindClick() - ImageSearch, Clicking, & More [Newest Version]
Thanks again. I tried both and they work great, but I now use only the second version: and
Code: Select all
FindClick(Image, "e n2")
Code: Select all
FindClick(Image, "n2")
Return to “Scripts and Functions (v1)”
Who is online
Users browsing this forum: No registered users and 77 guests