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

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

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

Post by milkygirl90 » 18 Mar 2021, 01:44

please don't mind me asking silly questions, is o20 the same as oTransBlack,20?

in any case, I tested both options from 0 - 2000 and still could not get it to work reliably..

User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

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

Post by boiler » 18 Mar 2021, 07:13

No, there is a huge difference between what the two things do and how they are used. When you use the 20 (or other number) option, you are allowing each pixel being checked to have each of its RGB color components within 20 shades of an exact match. Since each value of an RGB component ranges from 0 to 255, anything greater than 255 is meaningless. And using 255 will cause it to match anything because every color component will be within 255 of any other. Except for specific circumstances, you typically don’t want to use an allowable variation in the hundreds.

The Trans option is much different. You don’t just add it and expect it to help find an image. You are telling the search to disregard pixels of the specified color in your reference image. So for it to do anything in your case, you would need to modify your reference image using an image editor like MS Paint, and recolor the pixels you want it to ignore to a certain color, in this case black. You would paint over those grayish pixels on the edges of the icon that are rendered differently each time as well as a column of pixels to the left and right of that edge since they could be changing slightly too. And when you paint the new pixels, you have to make sure they are all purely that color, so you would have to use the pencil tool, not the brush tool, because the brush tool would paint shades of grey around the edges, and that would cause your image to never be found.

Although implementing the Trans option is relatively involved, it’s very powerful, and it is the answer for reliably finding this icon.

If you use both the Trans option and the allowable variation option, you are simply telling it to ignore pixels of the specified color as described above while also allowing the other pixels to be within the specified number of shades of each RGB component relative to the corresponding pixel in the reference image.

User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

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

Post by milkygirl90 » 22 Mar 2021, 20:04

ok, will try to digest what u mentioned above.

By the way, I found that using the code below makes composing an email very laggy in Gmail, probably due to it needing to check for image availability. Is there a better way to code this?

Code: Select all

#If WinActive("Gmail") && !FindClick("E:\Dropbox\Screenshots\AutoHotkey_2021-03-22_20-59-14.png", "n0 o60") ;Gmail Email View. If I don't see my Gmail avatar, then the hotkeys below will be valid 
Del::
c:: ;delete
SendRaw #
return

z::k ;previous conversation 
x::j ;next conversation 
w::PgUp
s::PgDn
return

User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

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

Post by boiler » 22 Mar 2021, 20:50

Yeah, that's going to cause it to perform an image search every time you press one of those keys and cause the lag. I guess you're saying the window title of "Gmail" isn't enough to determine when the hotkeys should be active or not. Is there something else more specific about the window title when your composing a message or whatever that would be true when the hotkeys are to be inactive? That would be a much better way. If not, then what I might do is have a hotkey that lets you turn the other hotkeys on and off so you can decide when they're active. You could do it with Suspend but that would turn off all other hotkeys in your script. If you just wanted to be able to toggle these particular hotkeys on and off, you could have it set a variable like below. You would press Ctrl+Esc (which can be whatever, of course) to activate/deactivate the hotkeys that are subject to the HKToggle variable's value.

Code: Select all

^Esc::
ToolTip, % "Hotkeys are " . ((HKToggle := !HKToggle) ? "active" : "inactive")
SetTimer, ToolTipOff, -2000
return

ToolTipOff:
ToolTip
return

#If WinActive("Gmail") && HKToggle 
^Esc::MsgBox, 

Del::
c:: ;delete
SendRaw #
return

z::k ;previous conversation 
x::j ;next conversation 
w::PgUp
s::PgDn

User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

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

Post by milkygirl90 » 22 Mar 2021, 21:19

yeah, there's no change in window title from conversation view mode to compose/reply mode.. ☹️

LongChair
Posts: 1
Joined: 08 May 2021, 03:35

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

Post by LongChair » 08 May 2021, 10:43

I am having some troubles with multiple image searches, that is with the “e” options.

When look to some image that has several occurrences aligned vertically, it seems it will find the topmost one, but not the ones that are in the same column below.

Did anyone notice this and would have a way to overcome this ?

User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

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

Post by milkygirl90 » 02 Aug 2021, 18:01

How do I get Findclick to ignore color variations, or even recognize 2 different color variations on the same pattern? Sample attached:

https://i.imgur.com/1WSEx7E.png
https://i.imgur.com/FxHuzf5.png
https://i.imgur.com/B4bwOBT.png

matej313
Posts: 4
Joined: 20 Nov 2021, 05:53

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

Post by matej313 » 20 Nov 2021, 11:55

Hello,
it doesnt work, i get this error... Can it be fixed?
003: # := " "
003: $ := "
"
002: {
1603: Exit (26.25)

Press [F5] to refresh.

Thank you

newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

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

Post by newcod3r » 09 Mar 2022, 04:12

Hi, I must have missed it in the docs - is there an option/modifier that allows me to continue executing the code only IF image is found? the closest I could find is the wait option only.

fona
Posts: 65
Joined: 07 Apr 2022, 06:43

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

Post by fona » 07 May 2022, 11:38

Hello,
How is this script different from AutomateMyTask created by Joe Glines?
https://www.the-automator.com/downloads/automatemytask/

Is it better than using just the pure ImageSearch? Maybe this one has a multi monitor option? Could you please tell me what are the advantages of this script?

User avatar
vSky
Posts: 80
Joined: 30 May 2022, 10:13

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

Post by vSky » 28 Jun 2022, 18:54

Hi, I'm having trouble using if and variable. Can you help me?

First Method;

Code: Select all

OnLoginProcces()
{
	if FindClick("C:\Login.png", "n", xLogin, y0)
	{
        Cheked()
  }
	else if FindClick("C:\TextCheck.png", "n", xLogin2, y2)
  {
	Send, sky
	}
}
What I've tried with trial and error management;

Code: Select all

Pic1 := "C:\Login.png"
if FindClick("C:\Login.png")
if FindClick(Pic1)
if FindClick(Pic1, "n")
if FindClick(Pic1, "n", xLogin, y0)
All of this When we do it this way, it opens the image creation window(FindClick()). It runs this command even though there is no FindClick() command.


Second Method;

Code: Select all

OnLoginProcces()
{
	FindClick("C:\Login.png", "n", xLogin, y0)
	FindClick("C:\NoahSystem.png", "n", xLogin2, y2)
	if (xLogin > 0)
	{
	xLogin := 0
        Cheked()
  }
	else if (xLogin2 > 0)
  {
	Send, sky
	xLogin2 := 0
	}
}
I wanted to create a trigger with coordinate changes. This method uses a lot of power and takes 20 seconds or less to run the command after the image is found.


So both methods didn't work. Most likely there is something wrong with my coding method. I would be glad if you help. Thank you.

Yelseppi
Posts: 3
Joined: 23 Dec 2022, 06:52

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

Post by Yelseppi » 23 Dec 2022, 06:57

Hey,

Absolutely love this library but would appreciate one additional change if possible: an option to change the ByRef coordinates from Screen to relative then they are returned? If not, would it be possible for me to edit FindClick.ahk on my end as to achieve this?

Many thanks in advance, a great piece of work.

newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

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

Post by newcod3r » 25 Jun 2023, 21:05

May I know how to use FindClick to find the X button WHILE ignoring the surrounding colors that come with it? Sample case below in MS Outlook. I'm trying to code a script to close all other calendars except my own.
image.png
image.png (2.34 KiB) Viewed 1167 times

newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

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

Post by newcod3r » 04 Nov 2023, 21:17

this thread seems dead by now. Is there any new script that supersedes Findclick?

All is well with this function but I do need some support.

Does anyone know how I can prioritize the imagesearch from top to bottom? Documentation only allows me to specify coordinates / offsets, but I don't have these info and can only sort by top to bottom instead.

User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

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

Post by boiler » 05 Nov 2023, 07:16

newcod3r wrote: Does anyone know how I can prioritize the imagesearch from top to bottom?
Do you mean you want to prioritize from bottom to top? Top to bottom is the default search direction for ImageSearch and for FindClick.

There is the d option in FindClick that lets you specify a different search direction. You can specify dleft, dright, or dbottom. However, to accomplish this, it finds all images and reports the result(s) as it if used that search direction, so it can be slow if there are multiple matches in the search rectangle.

newcod3r wrote: Documentation only allows me to specify coordinates / offsets, but I don't have these info and can only sort by top to bottom instead.
The d search direction option is covered in he FindClick documentation.

newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

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

Post by newcod3r » 05 Nov 2023, 08:00

that's weird. with this sample below, and taking a partial crop of the word "HD", it doesn't always select the first HD option. not sure how else I can improve it as I can't select using keystrokes.
image.png
image.png (182.44 KiB) Viewed 657 times

User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

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

Post by boiler » 05 Nov 2023, 08:41

ImageSearch (and FindClick is just a wrapper for ImageSearch) will always have a problem finding anti-aliased text. If you zoom in on each instance of "HD" and check the actual colors of each pixel using Window Spy, you'll see that they're actually rendered differently based on how the "smoothing" is achieved for each instance based on its location on the monitor. In this case it looks like the top two may be identical (their nominal positions must be the same relative to the "start" pixel where they are located), but the bottom one is different -- not to the eye, but based on the color values. Depending on what your "HD" reference image is, it may match only the bottom one in this case. In other cases, it may match none.

Fortunately in this situation, the smoothing is done in shades of gray -- it's often done with multiple colors that end up looking grey (or actually smoothed white edges) to the naked eye when next to each other -- so you may be able to find all of them if you just apply an appropriate allowable hue variation like 20 or so. It looks like in this case, it might even work with a lower number, but you shouldn't need to cut it too close.

You might want to try the FindText function, which uses a method of summarizing the text information in a way that can find it even when it contains these types of variations.

newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

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

Post by newcod3r » 05 Nov 2023, 09:09

hmm I actually used o30 all along but it didn't detect properly too.

ok, shall try FindText. Thanks!

Post Reply

Return to “Scripts and Functions (v1)”