image

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
SonGokuBg
Posts: 72
Joined: 27 Aug 2017, 12:40

image

03 Jul 2019, 06:00

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!
frd
Posts: 42
Joined: 19 Jul 2018, 10:01

Re: image

03 Jul 2019, 07:13

This should do the job:

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
Put your image on the same directory that you have your script.
SonGokuBg
Posts: 72
Joined: 27 Aug 2017, 12:40

Re: image

03 Jul 2019, 07:18

frd wrote:
03 Jul 2019, 07:13
This should do the job:

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
Put your image on the same directory that you have your script.
And how to do ut every few seconds ?
SonGokuBg
Posts: 72
Joined: 27 Aug 2017, 12:40

Re: image

03 Jul 2019, 07:44

not work with ''return''
frd
Posts: 42
Joined: 19 Jul 2018, 10:01

Re: image

03 Jul 2019, 07:56

SonGokuBg wrote:
03 Jul 2019, 07:18
frd wrote:
03 Jul 2019, 07:13
This should do the job:

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
Put your image on the same directory that you have your script.
And how to do ut every few seconds ?
Try this:

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
SonGokuBg
Posts: 72
Joined: 27 Aug 2017, 12:40

Re: image

03 Jul 2019, 09:26

frd wrote:
03 Jul 2019, 07:56
SonGokuBg wrote:
03 Jul 2019, 07:18
frd wrote:
03 Jul 2019, 07:13
This should do the job:

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
Put your image on the same directory that you have your script.
And how to do ut every few seconds ?
Try this:

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
what is wrong it only does 'if (ErrorLevel = 1)
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 
gregster
Posts: 9001
Joined: 30 Sep 2013, 06:48

Re: image

03 Jul 2019, 09:47

C:\Users\gogit\Desktop/AHKK.JPG
Wrong slash?! --> use \
SonGokuBg
Posts: 72
Joined: 27 Aug 2017, 12:40

Re: image

03 Jul 2019, 10:25

gregster wrote:
03 Jul 2019, 09:47
C:\Users\gogit\Desktop/AHKK.JPG
Wrong slash?! --> use \
If I use '\' instead of '/' ig give error
gregster
Posts: 9001
Joined: 30 Sep 2013, 06:48

Re: image

03 Jul 2019, 10:27

Which error? Is the path really correct?
/ is definitely wrong....
SonGokuBg
Posts: 72
Joined: 27 Aug 2017, 12:40

Re: image

03 Jul 2019, 11:03

gregster wrote:
03 Jul 2019, 10:27
Which error? Is the path really correct?
/ is definitely wrong....
Ah, sorry made mistake while trying to fix the script. Now it doesn't give error but still do only 'if (ErrorLevel = 1)
MouseClick, Left, 1819, 837,''
gregster
Posts: 9001
Joined: 30 Sep 2013, 06:48

Re: image

03 Jul 2019, 11:08

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:
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.
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: image

03 Jul 2019, 12:38

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.
SonGokuBg
Posts: 72
Joined: 27 Aug 2017, 12:40

Re: image

03 Jul 2019, 12:44

gregster wrote:
03 Jul 2019, 11:08
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:
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.
png didn't work too, I don't understand that below
SonGokuBg
Posts: 72
Joined: 27 Aug 2017, 12:40

Re: image

03 Jul 2019, 12:56

p.s the image is black and white
SonGokuBg
Posts: 72
Joined: 27 Aug 2017, 12:40

Re: image

03 Jul 2019, 17:23

It work when the image is only black screen
frd
Posts: 42
Joined: 19 Jul 2018, 10:01

Re: image

04 Jul 2019, 08:37

gregster wrote:
03 Jul 2019, 11:08
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:
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.
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?

And a question to OP: did you try with BMP?
SonGokuBg
Posts: 72
Joined: 27 Aug 2017, 12:40

Re: image

04 Jul 2019, 09:12

frd wrote:
04 Jul 2019, 08:37
gregster wrote:
03 Jul 2019, 11:08
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:
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.
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?

And a question to OP: did you try with BMP?
not work
SonGokuBg
Posts: 72
Joined: 27 Aug 2017, 12:40

Re: image

05 Jul 2019, 09:12

https://imgur.com/a/TW9Uiau That is the image I am trying
SonGokuBg
Posts: 72
Joined: 27 Aug 2017, 12:40

Re: image

06 Jul 2019, 13:02

help :cry: :cry:
gregster
Posts: 9001
Joined: 30 Sep 2013, 06:48

Re: image

06 Jul 2019, 13:40

frd wrote:
04 Jul 2019, 08:37
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?
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:
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.
[... ]
Is this for a program or website that would be available for testing?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AHK_user and 206 guests