Hello,
I am very beginner and can't find the answer in forum and guide.
How to make script to: if detect the chosen image on the screen to do X if not detect it to do Y?
Thanks!
image
Re: image
This should do the job:
Put your image on the same directory that you have your script.
Code: Select all
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
SetWorkingDir %A_ScriptDir%
ImageSearch, coordx, coordy, 0, 0, A_ScreenWidth, A_ScreenHeight, image.bmp
if (ErrorLevel = 2)
msgbox theres something wrong ; script is messed up
if (ErrorLevel = 1)
msgbox cant see it ; script is working, but the image isnt on the screen
if (ErrorLevel = 0)
MouseMove, coordx, coordy ; move your mouse to the exact image
Return
Re: image
And how to do ut every few seconds ?frd wrote: ↑03 Jul 2019, 07:13This should do the job:
Put your image on the same directory that you have your script.Code: Select all
CoordMode, Pixel, Screen CoordMode, Mouse, Screen SetWorkingDir %A_ScriptDir% ImageSearch, coordx, coordy, 0, 0, A_ScreenWidth, A_ScreenHeight, image.bmp if (ErrorLevel = 2) msgbox theres something wrong ; script is messed up if (ErrorLevel = 1) msgbox cant see it ; script is working, but the image isnt on the screen if (ErrorLevel = 0) MouseMove, coordx, coordy ; move your mouse to the exact image Return
Re: image
Try this:SonGokuBg wrote: ↑03 Jul 2019, 07:18And how to do ut every few seconds ?frd wrote: ↑03 Jul 2019, 07:13This should do the job:
Put your image on the same directory that you have your script.Code: Select all
CoordMode, Pixel, Screen CoordMode, Mouse, Screen SetWorkingDir %A_ScriptDir% ImageSearch, coordx, coordy, 0, 0, A_ScreenWidth, A_ScreenHeight, image.bmp if (ErrorLevel = 2) msgbox theres something wrong ; script is messed up if (ErrorLevel = 1) msgbox cant see it ; script is working, but the image isnt on the screen if (ErrorLevel = 0) MouseMove, coordx, coordy ; move your mouse to the exact image Return
Code: Select all
#Persistent
SetTimer, FindThatImage, 2000; every 2 seconds
return
FindThatImage:
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
SetWorkingDir %A_ScriptDir%
ImageSearch, coordx, coordy, 0, 0, A_ScreenWidth, A_ScreenHeight, image.bmp
if (ErrorLevel = 2)
msgbox theres something wrong ; script is messed up
if (ErrorLevel = 1)
msgbox cant see it ; script is working, but the image isnt on the screen
if (ErrorLevel = 0)
MouseMove, coordx, coordy ; move your mouse to the exact image
Return
Re: image
what is wrong it only does 'if (ErrorLevel = 1)frd wrote: ↑03 Jul 2019, 07:56Try this:SonGokuBg wrote: ↑03 Jul 2019, 07:18And how to do ut every few seconds ?frd wrote: ↑03 Jul 2019, 07:13This should do the job:
Put your image on the same directory that you have your script.Code: Select all
CoordMode, Pixel, Screen CoordMode, Mouse, Screen SetWorkingDir %A_ScriptDir% ImageSearch, coordx, coordy, 0, 0, A_ScreenWidth, A_ScreenHeight, image.bmp if (ErrorLevel = 2) msgbox theres something wrong ; script is messed up if (ErrorLevel = 1) msgbox cant see it ; script is working, but the image isnt on the screen if (ErrorLevel = 0) MouseMove, coordx, coordy ; move your mouse to the exact image Return
Code: Select all
#Persistent SetTimer, FindThatImage, 2000; every 2 seconds return FindThatImage: CoordMode, Pixel, Screen CoordMode, Mouse, Screen SetWorkingDir %A_ScriptDir% ImageSearch, coordx, coordy, 0, 0, A_ScreenWidth, A_ScreenHeight, image.bmp if (ErrorLevel = 2) msgbox theres something wrong ; script is messed up if (ErrorLevel = 1) msgbox cant see it ; script is working, but the image isnt on the screen if (ErrorLevel = 0) MouseMove, coordx, coordy ; move your mouse to the exact image Return
MouseClick, Left, 1819, 837,' although the image is there
Code: Select all
#Persistent
SetTimer, FindThatImage, 3000
return
FindThatImage:
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
SetWorkingDir %A_ScriptDir%
ImageSearch, coordx, coordy, 757, 470, 868, 576, C:\Users\gogit\Desktop/AHKK.JPG
if (ErrorLevel = 2)
msgbox theres something wrong ; script is messed up
if (ErrorLevel = 1)
MouseClick, Left, 1819, 837,
if (ErrorLevel = 0)
MouseClick, Left, 114, 62,
Sleep, 3000
return,
RButton::ExitApp
o::pause
Re: image
C:\Users\gogit\Desktop/AHKK.JPG
Wrong slash?! --> use \
Wrong slash?! --> use \
Re: image
Which error? Is the path really correct?
/ is definitely wrong....
/ is definitely wrong....
Re: image
I rarely use Imagesearch, but I know that a lossless format like bmp or png is usually better than lossy jpg.
Also try to play around with the options, like:
Also try to play around with the options, like:
https://www.autohotkey.com/docs/commands/ImageSearch.htm#Parameters wrote:*n (variation): Specify for n a number between 0 and 255 (inclusive) to indicate the allowed number of shades of variation in either direction for the intensity of the red, green, and blue components of each pixel's color. For example, *2 would allow two shades of variation. This parameter is helpful if the coloring of the image varies slightly or if ImageFile uses a format such as GIF or JPG that does not accurately represent an image on the screen. If you specify 255 shades of variation, all colors will match. The default is 0 shades.
Re: image
You will need a lot of variation to be using JPEGs AHKK.JPG Its just not worth the hassle its crap.
Change your search image to .png as Gregster mentioned already.
Change your search image to .png as Gregster mentioned already.
Re: image
png didn't work too, I don't understand that belowgregster wrote: ↑03 Jul 2019, 11:08I rarely use Imagesearch, but I know that a lossless format like bmp or png is usually better than lossy jpg.
Also try to play around with the options, like:https://www.autohotkey.com/docs/commands/ImageSearch.htm#Parameters wrote:*n (variation): Specify for n a number between 0 and 255 (inclusive) to indicate the allowed number of shades of variation in either direction for the intensity of the red, green, and blue components of each pixel's color. For example, *2 would allow two shades of variation. This parameter is helpful if the coloring of the image varies slightly or if ImageFile uses a format such as GIF or JPG that does not accurately represent an image on the screen. If you specify 255 shades of variation, all colors will match. The default is 0 shades.
Re: image
It work when the image is only black screen
Re: image
Hello there! As a side question, what would you to handle that kind of problem? Would you try pixelsearch or some other script like findclick? Or maybe findtext?gregster wrote: ↑03 Jul 2019, 11:08I rarely use Imagesearch, but I know that a lossless format like bmp or png is usually better than lossy jpg.
Also try to play around with the options, like:https://www.autohotkey.com/docs/commands/ImageSearch.htm#Parameters wrote:*n (variation): Specify for n a number between 0 and 255 (inclusive) to indicate the allowed number of shades of variation in either direction for the intensity of the red, green, and blue components of each pixel's color. For example, *2 would allow two shades of variation. This parameter is helpful if the coloring of the image varies slightly or if ImageFile uses a format such as GIF or JPG that does not accurately represent an image on the screen. If you specify 255 shades of variation, all colors will match. The default is 0 shades.
And a question to OP: did you try with BMP?
Re: image
not workfrd wrote: ↑04 Jul 2019, 08:37Hello there! As a side question, what would you to handle that kind of problem? Would you try pixelsearch or some other script like findclick? Or maybe findtext?gregster wrote: ↑03 Jul 2019, 11:08I rarely use Imagesearch, but I know that a lossless format like bmp or png is usually better than lossy jpg.
Also try to play around with the options, like:https://www.autohotkey.com/docs/commands/ImageSearch.htm#Parameters wrote:*n (variation): Specify for n a number between 0 and 255 (inclusive) to indicate the allowed number of shades of variation in either direction for the intensity of the red, green, and blue components of each pixel's color. For example, *2 would allow two shades of variation. This parameter is helpful if the coloring of the image varies slightly or if ImageFile uses a format such as GIF or JPG that does not accurately represent an image on the screen. If you specify 255 shades of variation, all colors will match. The default is 0 shades.
And a question to OP: did you try with BMP?
Re: image
https://imgur.com/a/TW9Uiau That is the image I am trying
Re: image
Hard to say, it depends on the program. These are surely options, like Imagesearch, but luckily I rarely have to handle cases where I need these.
So, I am not totally familiar with them and always have to look up how they work, when I need them. For my personal use cases, I mostly use browser automation and use COM, APIs or WebAPIs in the background - or get around with Send, Click and ControlSend etc.
SonGokuBg, I would probably try it here with a more cropped image (without the curved edges of the button in the image you posted), as long it shows an unique part of the target area. This could eliminate potential problems with the background around the button you are looking for... but like I said, I am not really an expert with Imagesearch:
Is this for a program or website that would be available for testing?https://www.autohotkey.com/docs/commands/ImageSearch.htm#Remarks wrote:A strategy that is sometimes useful is to search for a small clipping from an image rather than the entire image. This can improve reliability in cases where the image as a whole varies, but certain parts within it are always the same. One way to extract a clipping is to:
1. Press Alt+PrintScreen while the image is visible in the active window. This places a screenshot on the clipboard.
[... ]
Who is online
Users browsing this forum: AHK_user and 206 guests