Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

FindClick() 2nd Edition


  • Please log in to reply
66 replies to this topic
berban
  • Members
  • 202 posts
  • Last active: Apr 12 2019 01:08 AM
  • Joined: 30 Dec 2009
New Forum Post: https://autohotkey.c...php?f=6&t=18719
The code linked there is the same but the post isn't archived so you can reply to it there.











OLD POST:

A script that combines many uses of the AutoHotkey ImageSearch command into one powerful and easy-to-use function. Older version can be seen here. (Download older version here - the code is messed up in the forum post.)

Script: https://onedrive.liv...ithint=file,ahk
Documentation: https://onedrive.liv...ithint=file,pdf

(urls are from Microsoft OneDrive)

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

The script is basically complete save for some of the description text in the debugger module. The documentation is a work in progress but covers the main topics of using the function.

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:
tJFyn5X.png

Image of the debugger gui:
nFONSi8.png

Image of the function in my standard library:
09Yl8Tt.png

(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.)


Find me on the new AutoHotkey forums and send me a message if you have a question about any of the scrips I've posted to this forum!


safmy
  • Members
  • 7 posts
  • Last active: Jul 08 2015 03:52 PM
  • Joined: 03 Feb 2013

Any chance of an example? I had this error when I tried to add the option "Stay"

 

error_zps634debd8.png



Larctic
  • Members
  • 303 posts
  • Last active: May 10 2016 04:56 PM
  • Joined: 21 Jul 2012

I would like to ask, whether this function can find pictures in a minimized window?



berban_
  • Members
  • 202 posts
  • Last active: Aug 05 2014 11:52 PM
  • Joined: 16 Mar 2011

I would like to ask, whether this function can find pictures in a minimized window?

 

Unfortunately it cannot. ImageSearch only deals with on-screen images, that is, images that are currently being rendered by your computer's graphics processor and being output to a display device of some sort. (However, the display device doesn't need to be turned on.)

 

 

 

Any chance of an example? I had this error when I tried to add the option "Stay"

 

error_zps634debd8.png

 

Thanks for posting this samfy! I just added this error box and wasn't hoping to ever see it needed!

I'd like you to answer a couple of questions so I can get a better idea of why this happened, and hopefully how to fix it.

  1. What was the code of the imagefile & options you used for findclick when this error came up? Using the "stay" option should not incur this error. Does it happen every time you use findclick?
  2. Do you have access to the directory shown in the error dialog box? On a related note, why is your root dir D:\ ? Just curious.
  3. Try calling findclick with no parameters, e.g. FindClick(). Then when the window comes up, press pause and press test. Does the error come up when you press "test" ?
  4. What version of AutoHotkey are you using? (unicode/ansi, x64/x86)? What operating system are you using? 64 bit?

I really appreciate your help in trying to iron out the kinks in this function!!



Larctic
  • Members
  • 303 posts
  • Last active: May 10 2016 04:56 PM
  • Joined: 21 Jul 2012
Thank you for your reply.
I tried to use other methods to improve this feature,
I found three scripts, it seems that they can be combined.
 
1 use DWM thumbnail, you can get a complete image of the minimized window.
2  "Gdip.ahk" analyze images pixel comparison.
In-memory Window Capture, but invalid on the minimized window.
 
 
DWM thumbnail,But I do not know how to get the bitmap
 
#SingleInstance force
#NoEnv
SetBatchLines,-1

OnExit exit
gui,new,+hwndtarget AlwaysOnTop
gui,show,% "w" A_ScreenWidth/1.5 " h" A_ScreenHeight/1.5,target

VarSetCapacity(phThumbnailId,A_PtrSize,0)
VarSetCapacity(pSize,8)
D_left := 0 , D_top := 0 , D_right := A_ScreenWidth , D_bottom := A_ScreenHeight
R_left := 0 , R_top := 0 , R_right := A_ScreenWidth , R_bottom := A_ScreenHeight
opacity := 255 , fVisible := 1 , fSourceClientAreaOnly := 1
source := WinExist("ahk_class Progman")
hr := Dllcall("Dwmapi\DwmRegisterThumbnail","uint",target,"uint",source,"ptr",&phThumbnailId)
if success(hr)
{
        hThumbnailId := NumGet(phThumbnailId)
        VarSetCapacity(ptnProperties,45,0)
        DWM_TNP_RECTDESTINATION := 1 , DWM_TNP_RECTSOURCE := 2 , DWM_TNP_OPACITY := 4 , DWM_TNP_VISIBLE := 8 , DWM_TNP_SOURCECLIENTAREAONLY := 16 
        NumPut(DWM_TNP_RECTDESTINATION|DWM_TNP_RECTSOURCE|DWM_TNP_OPACITY|DWM_TNP_VISIBLE|DWM_TNP_SOURCECLIENTAREAONLY,ptnProperties)
        if DWM_TNP_RECTDESTINATION 
                NumPut(D_left,ptnProperties,4,"Int") , NumPut(D_top,ptnProperties,8,"Int") , NumPut(D_right,ptnProperties,12,"Int") , NumPut(D_bottom,ptnProperties,16,"Int")
        if DWM_TNP_RECTSOURCE 
                NumPut(R_left,ptnProperties,20,"Int") , NumPut(R_top,ptnProperties,24,"Int") , NumPut(R_right,ptnProperties,28,"Int") , NumPut(R_bottom,ptnProperties,32,"Int")
        if DWM_TNP_OPACITY 
                NumPut(opacity,ptnProperties,36,"uchar")
        if DWM_TNP_VISIBLE 
                NumPut(fVisible,ptnProperties,37,"Int")
        if DWM_TNP_SOURCECLIENTAREAONLY
                NumPut(fSourceClientAreaOnly,ptnProperties,41,"Int")
  
        hr := Dllcall("Dwmapi\DwmUpdateThumbnailProperties","uint",hThumbnailId,"ptr",&ptnProperties)

      MsgBox % StrLen(phThumbnailId)
        if success(hr)
                {
                }
}
return

GuiClose:
Esc::
exit:
if hThumbnailId
        hr := Dllcall("Dwmapi\DwmUnregisterThumbnail","uint",hThumbnailId)
ExitApp

success(hr)
{
        if hr
                msgbox, Error code : %hr%
        return !hr
}

 

 



Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

If there are 17 instances of the same exact image on the screen, how do you select the 4th instance ONLY and ignore the rest?



berban_
  • Members
  • 202 posts
  • Last active: Aug 05 2014 11:52 PM
  • Joined: 16 Mar 2011

Thank you for your reply.
I tried to use other methods to improve this feature,
I found three scripts, it seems that they can be combined.

 

Thanks for your help Larctic but I don't think I will be able to incorporate any of those features into this function. As a student I have limited time and want to focus on refining the code & documentation for findclick before I add new features.



berban_
  • Members
  • 202 posts
  • Last active: Aug 05 2014 11:52 PM
  • Joined: 16 Mar 2011

If there are 17 instances of the same exact image on the screen, how do you select the 4th instance ONLY and ignore the rest?

 

Good question. The answer is that you have to write some of your own AutoHotkey code to interpret the coordinates that FindClick gives you. I added an example to the documentation https://www.cubby.co...7/FindClick.pdf - you can find it on the last page.

 

By the way your avatar is cool :)



Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

Perfect! I did the following and your script works like a charm! Thanks, you are awesome!

MyImage := "C:\...\FindClick_btn_run_query_Coordinates\btn_run_query.gif"
i := 4

Results := FindClick(MyImage, "n e")

MsgBox, % Results ; For testing purpose

Loop, Parse, Results, `n
If (A_Index = i) {
StringSplit, Coords, A_LoopField, `,
MsgBox, The coordinates are (%Coords1%,%Coords2%)
Break
}

MsgBox, The coordinates are (%Coords1%,%Coords2%) ; For testing purpose

Click, %Coords1%,%Coords2% ; Done!


safmy
  • Members
  • 7 posts
  • Last active: Jul 08 2015 03:52 PM
  • Joined: 03 Feb 2013

Unfortunately it cannot. ImageSearch only deals with on-screen images, that is, images that are currently being rendered by your computer's graphics processor and being output to a display device of some sort. (However, the display device doesn't need to be turned on.)

 

 

 

 

Thanks for posting this samfy! I just added this error box and wasn't hoping to ever see it needed!

I'd like you to answer a couple of questions so I can get a better idea of why this happened, and hopefully how to fix it.

  1. What was the code of the imagefile & options you used for findclick when this error came up? Using the "stay" option should not incur this error. Does it happen every time you use findclick?
  2. Do you have access to the directory shown in the error dialog box? On a related note, why is your root dir D:\ ? Just curious.
  3. Try calling findclick with no parameters, e.g. FindClick(). Then when the window comes up, press pause and press test. Does the error come up when you press "test" ?
  4. What version of AutoHotkey are you using? (unicode/ansi, x64/x86)? What operating system are you using? 64 bit?

I really appreciate your help in trying to iron out the kinks in this function!!

 

 

It's Safmy.

 

1. The code is at the end, no options added. It didn't happen the first time I tried it, it's slightly temperamental I can't seem to replicate the condition in which it works. 

2. I installed a second windows (64 bit) onto my D:\, my C: has the 32 bit version. I do have access to the directory.

3. Yes it does, the code below illustrates that.

4. 64 bit unicode is installed. My operating system is 64 bit.

 

I love your funciton by the way. I do a lot of image searches and this is a lacking function I think. Pullover's recorder is the next best thing I've got.

 

;#Include, %A_ScriptDir%\FindClick.ahk

^Esc::ExitApp

^R::Reload
F6::FindClick()


Larctic
  • Members
  • 303 posts
  • Last active: May 10 2016 04:56 PM
  • Joined: 21 Jul 2012

Thanks, I will continue to look for the solution.



berban
  • Members
  • 202 posts
  • Last active: Apr 12 2019 01:08 AM
  • Joined: 30 Dec 2009

It's Safmy.

1. The code is at the end, no options added. It didn't happen the first time I tried it, it's slightly temperamental I can't seem to replicate the condition in which it works.
2. I installed a second windows (64 bit) onto my D:\, my C: has the 32 bit version. I do have access to the directory.
3. Yes it does, the code below illustrates that.
4. 64 bit unicode is installed. My operating system is 64 bit.


Thanks for all the help you've been, Samfy. Unfortunately I haven't been able to reproduce your error. I tested it again with AutoHotkey x64 (I'm already using 64 bit windows) with no errors building the image file.
I'm wondering if maybe there is some issue with your temporary dir? I.e., why is it the "short version" of the path (it contains "ADMIN1~1"). I was wondering if you could change the following declaration in the FindClick code (should be around line #1250):
TempFile = %A_Temp%\%A_ThisFunc%Temp.png
with some other simpler name like this:
TempFile = C:\temp.png
and see if that makes any difference?

Find me on the new AutoHotkey forums and send me a message if you have a question about any of the scrips I've posted to this forum!


berban
  • Members
  • 202 posts
  • Last active: Apr 12 2019 01:08 AM
  • Joined: 30 Dec 2009

Perfect! I did the following and your script works like a charm!

 

Glad to help!


Find me on the new AutoHotkey forums and send me a message if you have a question about any of the scrips I've posted to this forum!


safmy
  • Members
  • 7 posts
  • Last active: Jul 08 2015 03:52 PM
  • Joined: 03 Feb 2013

It's Safmy.

 

Works once and then this pops up.

error_zpsded73520.png

 

And when I try the options like "Stay" this pops up.

 

2013-02-08_221458_zpsa5f5964f.png



Frits
  • Members
  • 6 posts
  • Last active: Aug 20 2014 10:17 PM
  • Joined: 23 Mar 2013

Great script,

 

Is it possible, to findclick 2 image's of many whit options ?

opt = a14, o128 e
FindClick("Ris_coin.bmp", opt)

 

whit "e" all will be found, i have try ed w400,200 and sleep200

but still all will be found, 

I need to click 2 of them not all

 

of cores i can call the funtion twice, but still