Image find and ctrl click loop
Image find and ctrl click loop
trying to create a script that will find an image on screen and control click it till there are no more or it hits 44. having troubles having it find the image match on screen
Re: Image find and ctrl click loop
Use ImageSearch. Feel free to post your script to get feedback about it.
Re: Image find and ctrl click loop
Code: Select all
f16::
coordMode,pixel
^1::
ImageSearch,ix,iy,0,0,2383,1137,G:\Mega\Autohotkey\Images\22800.png
msgbox % "Errorlevel: " . errorlevel . "`nix: " . ix . "`niy: " . iy
MouseClick, left, ix+20, iy+20
return
I have this. It will find the picture as long as it is in an windows photo window. I tried it within a program the same exact picture and it wont detect it. Along with this is will not click on the image.
Re: Image find and ctrl click loop
Also thanks for any help!
Re: Image find and ctrl click loop
By default, coordinates are relative to the active window-- whichever window is active when you trigger the routine. If your image is visible, it's likely out of the range that you specified. To modify the reference point for the coordinates, use CoordMode.
Re: Image find and ctrl click loop
So I went through and made sure my coordinates were gather when the program window was active. Changed the cords in the script to reflect the proper ones and I am still getting error code one.
[Mod edit: [code][/code] tags added.]
I cant spot what is wrong
Code: Select all
f16::
^1::
ImageSearch,ix,iy,1685,102,2539,1248,G:\Mega\Autohotkey\Images\22800.png
msgbox % "Errorlevel: " . errorlevel . "`nix: " . ix . "`niy: " . iy
MouseClick, left, ix+20, iy+20
return
I cant spot what is wrong

Re: Image find and ctrl click loop
Code: Select all
^!a::
Loop
{
WinActivate, EST.exe
CoordMode Pixel
CoordMode Mouse ;
ImageSearch, FoundX, FoundY, 1690,345,2545,1339, *25 G:\Mega\Autohotkey\Images\22800.png
sleep, 100
err := Errorlevel
If (err = 0)
{
;MsgBox Image Found
;Sleep, 500
;Click %FoundX%, %FoundY%
MouseMove, %fx%, %fy%
Sleep 500
click
sleep,500
break
}
Sleep, 500
}
return
Found this on the forums and tried it but to no avail. Could it be a problem with the program and AHK cant match the image?
Last edited by gregster on 26 Jan 2021, 12:49, edited 1 time in total.
Reason: [code] tags added. Please use them yourself. Thank you!
Reason: [code] tags added. Please use them yourself. Thank you!
Re: Image find and ctrl click loop
Since the script does not work, pare it down: start with a static image that you want to find. Display it on your screen, say, with an image editor. Remove the hue variation option. Remove loop, mouse move, and click. You just want to get image search working. Run Window Spy. Activate your window. Check coordinates. Next, see if the script identifies your image.
This process usually narrows down the problem. In almost all cases, one of the following problems is occurring: file does not exist, images are not exactly the same, or coordinate reference point is misstated.
If it does not work, you can use a small portion of a new screenshot as your test file.
This process usually narrows down the problem. In almost all cases, one of the following problems is occurring: file does not exist, images are not exactly the same, or coordinate reference point is misstated.
Code: Select all
file = G:\Mega\Autohotkey\Images\22800.png
If !FileExist(file) {
MsgBox, 48, Error, File not found.`n`n%file%
Return
}
CoordMode, Pixel
ImageSearch, x, y, 0, 0, A_ScreenWidth, A_ScreenHeight, %file%
MsgBox, 0, Result, %file%`n`nx = %x%`ny = %y%
Re: Image find and ctrl click loop
Okay so it can find the image anywhere on the screen but the moment I go back into the program it cannot find it. I made the screen shot even smaller to see if it can identify a smaller section with not luck. So it has to be that the images are not exactly the same even though I am clipping it from the program itself into a image file.
Re: Image find and ctrl click loop
Which coordinates were identified as found? Are they within your search range? If so, then yes, perhaps the image is changing.
Re: Image find and ctrl click loop
I changed the cords to the whole screen and yes it found it and would output a message box with the x and y when not in the program
Re: Image find and ctrl click loop
OK, so if you are using CoordMode, Pixel, the search should also succeed with your program window active, as long as you are searching the entire screen, the image is visible, and the file matches the image.
Re: Image find and ctrl click loop
managed to get it to work by giving a pixel variation *10
Do you know if I can make it repeat a certain amount of time or until no more matches are found?
Do you know if I can make it repeat a certain amount of time or until no more matches are found?
Re: Image find and ctrl click loop
Is there a way to control click as well. This causes the control to become constantly pressed.
[Mod edit: [code][/code] tags added.]
Code: Select all
f15::ExitApp
f16::
Loop,44{
coordMode,pixel
^1::
ImageSearch,ix,iy,0,0,2383,1137,*10 G:\Mega\Autohotkey\Images\28000.png
Send, {Control down}
sleep,100
MouseClick,Left, ix+20, iy+20
sleep,100
Send, {Control up}
}
return
Re: Image find and ctrl click loop
One idea is below.
Code: Select all
F3::
CoordMode, Pixel
CoordMode, Mouse
Loop, 44 {
ImageSearch, ix, iy, 0, 0, 2383, 1137, *10 G:\Mega\Autohotkey\Images\28000.png
If !ErrorLevel {
MouseMove, ix + 20, iy + 20
Send ^{LButton}
} Else Sleep, 300
} Until (ix > "")
Return
Re: Image find and ctrl click loop
Will try when I get home! Can I use the error level 1 to have the script then search for a 2nd picture?
Re: Image find and ctrl click loop
Yes, sure.