Find image and click

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
JustUs3r
Posts: 21
Joined: 22 Apr 2018, 09:49

Find image and click

22 Apr 2018, 09:57

It's possible to find image (1) and click on (2)? And if (1) doesn't on the screen so ignore this?

Image
JustUs3r
Posts: 21
Joined: 22 Apr 2018, 09:49

Re: Find image and click

22 Apr 2018, 10:11

Also position of (2) may be changed at random position
JustUs3r
Posts: 21
Joined: 22 Apr 2018, 09:49

Re: Find image and click

22 Apr 2018, 10:16

Uh, forget about it. I need to find image with 1 and click on the 2. That's all.
Sheldz
Posts: 6
Joined: 21 Apr 2018, 10:55

Re: Find image and click

22 Apr 2018, 11:15

ImageSearch, x, y, 0, 0, A_ScreenWidth, A_ScreenHeight, Number1.jpg \\ this can be in the same space as the script as Number1.jpg or it can be in a directory elsewhere E:\Pictures\Number1.jpeg
MouseClick, left, %x%, %y%

Take a full screenshot of that and open up paint or an editor of your choice and crop it for number 1,2 or 3 and then save accordingly.
JustUs3r
Posts: 21
Joined: 22 Apr 2018, 09:49

Re: Find image and click

22 Apr 2018, 14:14

Sheldz wrote:ImageSearch, x, y, 0, 0, A_ScreenWidth, A_ScreenHeight, Number1.jpg \\ this can be in the same space as the script as Number1.jpg or it can be in a directory elsewhere E:\Pictures\Number1.jpeg
MouseClick, left, %x%, %y%

Take a full screenshot of that and open up paint or an editor of your choice and crop it for number 1,2 or 3 and then save accordingly.
Ok, thanks
JustUs3r
Posts: 21
Joined: 22 Apr 2018, 09:49

Re: Find image and click

22 Apr 2018, 14:47

But I need if 1st picture exist on the screen then click on the 2nd picture. How to do it? 2nd picture can be at random position

It's like:
If 1st picture and 2nd found then click on 2nd.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Find image and click

22 Apr 2018, 15:39

you need to perform 2 ImageSearches:
one to figure out if Number1.jpg is visible on the screen and whether to proceed with the execution
and a second one to find the location of Number2.jpg
JustUs3r
Posts: 21
Joined: 22 Apr 2018, 09:49

Re: Find image and click

23 Apr 2018, 07:22

swagfag wrote:you need to perform 2 ImageSearches:
one to figure out if Number1.jpg is visible on the screen and whether to proceed with the execution
and a second one to find the location of Number2.jpg
Yeah, if 1st picture and 2nd picture are found on the screen then click on 2nd. But if 1st picture is not found so just don't do anything. I don't know how to do it xd
Someone help me.
JustUs3r
Posts: 21
Joined: 22 Apr 2018, 09:49

Re: Find image and click

23 Apr 2018, 07:27

1::
ImageSearch, x, y, 0, 0, A_ScreenWidth, A_ScreenHeight, Picture1.jpg
If errorlevel = 0
Imagesearch, x, y, 0, 0, A_ScreenWidth, A_ScreenHeight, Picture2.jpg
click, %x%, %y%
if errorlevel = 1
Imagesearch, x, y, 0, 0, A_ScreenWidth, A_ScreenHeight, Picture3.jpg
If errorlevel = 0
Imagesearch, x, y, 0, 0, A_ScreenWidth, A_ScreenHeight, Picture4.jpg
click, %x%, %y%
if errorlevel = 1
Imagesearch, x, y, 0, 0, A_ScreenWidth, A_ScreenHeight, Picture5.jpg...

(I don't how to write this, but there is another loop of finding images. If 1st picture is not found, so find picture 3 e.t.c.)
JustUs3r
Posts: 21
Joined: 22 Apr 2018, 09:49

Re: Find image and click

23 Apr 2018, 13:17

Maybe I should try this?

Code: Select all

1::

loop,
{
ImageSearch, x, y, 0, 0, A_ScreenWidth, A_ScreenHeight, Picture1.jpg
If errorlevel = 0
Imagesearch, x, y, 0, 0, A_ScreenWidth, A_ScreenHeight, Picture2.jpg
click, %x%, %y%
if errorlevel = 1
Imagesearch, x, y, 0, 0, A_ScreenWidth, A_ScreenHeight, Picture3.jpg
If errorlevel = 0
Imagesearch, x, y, 0, 0, A_ScreenWidth, A_ScreenHeight, Picture4.jpg
click, %x%, %y%
if errorlevel = 1
Imagesearch, x, y, 0, 0, A_ScreenWidth, A_ScreenHeight, Picture5.jpg
If errorlevel = 0
Imagesearch, x, y, 0, 0, A_ScreenWidth, A_ScreenHeight, Picture6.jpg
click, %x%, %y%
If errorlevel = 1
}
return

2::pause
Someone can send the code? Because I think I don't fully understand function "ImageSearch" or I'm doing right?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Find image and click

23 Apr 2018, 14:35

here u have the super not recommended 1 minute copy-paste unmaintainable untestable undebuggable un-in-2days-from-now-recallable and un-in-the-not-so-distant-future-look-at-able version
Spoiler
JustUs3r
Posts: 21
Joined: 22 Apr 2018, 09:49

Re: Find image and click

23 Apr 2018, 15:50

swagfag wrote:here u have the super not recommended 1 minute copy-paste unmaintainable untestable undebuggable un-in-2days-from-now-recallable and un-in-the-not-so-distant-future-look-at-able version
Spoiler
Thanks, it works. And sorry for flood. But when I enable script in program it doesn't work. Why?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Find image and click

23 Apr 2018, 17:18

swagfag wrote:unmaintainable untestable undebuggable
:thinking:

have you replaced PictureX.jpg with, for example, the full path to your image file?
barring that it could be due to any number of reasons, including but not limited to: your imagefile cant be located, your imagefile cant be opened, your imagefile doesnt match whats on the screen, your imagefile does match whats on the screen but clicks at the wrong location(See CoordMode in the docs), your imagesearch is too slow and cant keep up with the changes(too many pixels to query, too large of a image to match)

to run one must walk first, so why dont you take a look at the example in the ImageSearch docs and test whether youre able to perform 1 successfully to begin with

i dont know what your use case is, it might be that imagesearching simply doesnt lend itself to it well(translucency/opacity comes to mind)
JustUs3r
Posts: 21
Joined: 22 Apr 2018, 09:49

Re: Find image and click

24 Apr 2018, 15:11

swagfag wrote:
swagfag wrote:unmaintainable untestable undebuggable
:thinking:

have you replaced PictureX.jpg with, for example, the full path to your image file?
barring that it could be due to any number of reasons, including but not limited to: your imagefile cant be located, your imagefile cant be opened, your imagefile doesnt match whats on the screen, your imagefile does match whats on the screen but clicks at the wrong location(See CoordMode in the docs), your imagesearch is too slow and cant keep up with the changes(too many pixels to query, too large of a image to match)

to run one must walk first, so why dont you take a look at the example in the ImageSearch docs and test whether youre able to perform 1 successfully to begin with

i dont know what your use case is, it might be that imagesearching simply doesnt lend itself to it well(translucency/opacity comes to mind)
Thanks for the answer. I'll try it tomorrow and I'll reply here. So my script can work incorrect because i haven't written full path to image? I don't think that my image transparent.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 125 guests