Search for two images

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
canga
Posts: 8
Joined: 21 Apr 2018, 11:35

Search for two images

22 Apr 2018, 05:16

I have this code where I do a search for an image and executes the command.

Now I would like to do an "if and", then:
- search for the first image, if it finds it, look for the second one
- look for the second one, if it does not find it back in search of the first image

how can I do?

Code: Select all

Loop
{
   Loop
    {
        CoordMode, Pixel, Window
        ImageSearch, FoundX, FoundY, 855, 747, 914, 788, C:\image.png
        If ErrorLevel = 0
        	SoundBeep
    }
    Until ErrorLevel = 0
}
garry
Posts: 3763
Joined: 22 Dec 2013, 12:50

Re: Search for two images

22 Apr 2018, 10:50

example with 4 pictures , start with F2
3th picture name is wrong so clicks picture-1+2 AND picture-4

Code: Select all

;- example shows 4 pictures
;- 3th picture name is wrong so clicks picture-1+2 AND picture-4
;----------------------------------------------------------------------------
#Warn
#NoEnv                        ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode,Input                ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir, %A_ScriptDir%  ; Ensures a consistent starting directory.
CoordMode,Pixel,Screen
CoordMode,Mouse,Screen

;-------------------------------------------------------------
i=0
ur1=https://autohotkey.com/boards/images/flags/russia.png
SplitPath,ur1, name1, dir1, ext, name_no_ext, drive
f1 =%a_scriptdir%\%name1%

ur2=https://autohotkey.com/boards/images/flags/germany.png
SplitPath,ur2, name2, dir2, ext, name_no_ext, drive
f2 =%a_scriptdir%\%name2%

ur3=https://autohotkey.com/boards/images/flags/china.png
SplitPath,ur3, name3, dir3, ext, name_no_ext, drive
f3 =%a_scriptdir%\%name3%
f3a:=""     ;- wrong name so search next picture

ur4=https://autohotkey.com/boards/images/flags/france.png
SplitPath,ur4, name4, dir4, ext, name_no_ext, drive
f4 =%a_scriptdir%\%name4%


ifnotexist,%f1%
  urldownloadtofile,%ur1%,%f1%
ifnotexist,%f2%
  urldownloadtofile,%ur2%,%f2%
ifnotexist,%f3%
  urldownloadtofile,%ur3%,%f3%
ifnotexist,%f4%
  urldownloadtofile,%ur4%,%f4%

;---------------------------------------------------------------
Gui,add,picture, gA1 x10  y10  ,%f1%
Gui,add,picture, gA2 x90  y10  ,%f2%
Gui,add,picture, gA3 x170 y10  ,%f3%
Gui,add,picture, gA4 x250 y10  ,%f4%
gui,show, x100 y10 h70 w300 ,Use F2 to search Picture
return
guiclose:
exitapp
a1:
msgbox, 262208, ,Clicked Picture %name1%,2
return
a2:
msgbox, 262208, ,Clicked Picture %name2%,2
return
a3:
msgbox, 262208, ,Clicked Picture %name3%,2
return
a4:
msgbox, 262208, ,Clicked Picture %name4%,2
return


f2::
ImageSearch,xf,yf,0,0,%a_screenwidth%,%a_screenheight%, *TransBlack %f1%
picx=%name1%
gosub,errorx

ImageSearch,xf,yf,0,0,%a_screenwidth%,%a_screenheight%, *TransBlack %f2%
picx=%name2%
gosub,errorx

ImageSearch,xf,yf,0,0,%a_screenwidth%,%a_screenheight%, *TransBlack %f3a%    ;- wrong name for TEST
picx=%name3%
gosub,errorx

ImageSearch,xf,yf,0,0,%a_screenwidth%,%a_screenheight%, *TransBlack %f4%
picx=%name4%
gosub,errorx
msgbox, 262208, ,FINISHED
return

errorx:
i++
if errorlevel=1
  {
  msgbox, 262208, ,Error`nTry with next picture in 3 seconds,3
  return
  }
else if errorlevel=2
  {
  msgbox, 262208, ,Picture %picx% not found`nNow continue in 3 seconds with next-picture,3
  return
  }
MouseMove,%xf%,%yf%,
ToolTip,Here is the picture %picx%
sleep,2500
tooltip
MouseClick,left,%xf%,%yf%       ;- click on x-picture
return
;====================== END script =================================

SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

Re: Search for two images

22 Apr 2018, 12:27

Something like this?:

Code: Select all

CoordMode, Pixel, Window

loop
{
    ImageSearch, FoundX, FoundY, 855, 747, 914, 788, C:\image.png
    if (ErrorLevel == 0) ; Image found - search for another
    {
        ImageSearch, FoundX2, FoundY2, 855, 747, 914, 788, C:\image2.png
        if (ErrorLevel == 0) ; Second image found
        {
            ; do stuff
        }
    }
}
Use

Code: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.
canga
Posts: 8
Joined: 21 Apr 2018, 11:35

Re: Search for two images

25 Apr 2018, 12:33

I have a problem that I can not solve with pulover's macro creator.

I'm performing a looped image search, found the image and run a macro.
At the moment I have the search for a first image, if I find the second one.

I would like to do this:
- find the first image, if found
- find any of three images, if at least one is found then run macro

my current macro is:

Code: Select all

01|[Goto]|BloccaRefresh|1|0|Goto|||||
2|[LoopStart]|LoopStart|0|0|Loop|||||
3|WinActivate||1|333|WinActivate|e|||
4|Play Sound, Continue, FoundX, FoundY, 0|853, 745, 916, 794, *5 C:\a automate\x64\MacroCreator\Screenshots\Screen_20180423084434.png|1|0|ImageSearch|UntilFound|Window|||
5|If Image/Pixel Found||1|0|If_Statement|||||
6|Play Sound, Continue, FoundX, FoundY, 0|148, 745, 687, 804, *100 C:\a automate\x64\MacroCreator\Screenshots\Screen_20180423085130.png|1|0|ImageSearch|UntilFound|Window|||
7|If Image/Pixel Found||1|0|If_Statement|||||
8|[Goto]|Macro1|1|0|Goto|||||
9|[End If]|EndIf|1|0|If_Statement|||||
10|[End If]|EndIf|1|0|If_Statement|||||
12|[LoopEnd]|LoopEnd|1|0|Loop|||||
How can I change?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, mcd, Nerafius, RandomBoy, Rohwedder and 102 guests