only white in specified area ? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jsjcjsjc
Posts: 56
Joined: 25 May 2019, 03:11

only white in specified area ?

Post by jsjcjsjc » 27 Jan 2023, 06:33

Hi
I have a question regarding the "PixelSearch".
My question is how to know that there is only white in the specified area ?
here is my code, but not correct. it can help me find white color, but My need is to know that there is only white in the specified area.
could you please help me with it ?
Thanks in advance.

Code: Select all

CoordMode, Mouse, Screen

Loop
{
    MouseGetPos, x, y
    PixelSearch, FoundX, FoundY, x-50, y-50, x+50, y+50, 0xFFFFFF, 0, Fast
    if ErrorLevel
        MsgBox, NO
    else
        MsgBox, YES
}


wer
Posts: 57
Joined: 29 Nov 2022, 21:28

Re: only white in specified area ?

Post by wer » 27 Jan 2023, 07:51

Code: Select all

/*
you could take a screenshot of this "specified area"
so you got a "totally white picture.png"
*/
CoordMode, Mouse, Screen
CoordMode, Pixel, Screen

Loop
{
    sleep, 1000
    MouseGetPos, x, y
    msgbox,,, % x " " y, 1
    ImageSearch, up_left_x, up_left_y, 0, 0, A_ScreenWidth, A_ScreenHeight, totally white picture.png
    msgbox,,, % up_left_x " " up_left_y, 1
    if ((x-50)!=up_left_x and (y-50)!=up_left_y)
        MsgBox, NO
    else
        MsgBox, YES
}

User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: only white in specified area ?

Post by boiler » 27 Jan 2023, 07:58

@wer — It would be faster and eliminate the need to check the resulting location (just check ErrorLevel) if you set the search rectangle for ImageSearch to be the same as the same as the “specified” area instead of the whole screen.

Actually, it’s necessary that you do this, otherwise ImageSearch could find the white rectangle elsewhere on the screen (higher up or to the left of it) and it would fail your location test and never move on to potentially find the desired location since it only finds the first match.

wer
Posts: 57
Joined: 29 Nov 2022, 21:28

Re: only white in specified area ?  Topic is solved

Post by wer » 27 Jan 2023, 08:15

boiler wrote:
27 Jan 2023, 07:58
@wer — It would be faster and eliminate the need to check the resulting location (just check ErrorLevel) if you set the search rectangle for ImageSearch to be the same as the same as the “specified” area instead of the whole screen.

Actually, it’s necessary that you do this, otherwise ImageSearch could find the white rectangle elsewhere on the screen (higher up or to the left of it) and it would fail your location test and never move on to potentially find the desired location since it only finds the first match.
right sir, should be like:

Code: Select all

ImageSearch, up_left_x, up_left_y, x-50, y-50, x+50, y+50, totally white picture.png
my mistake, thanks for teaching

jsjcjsjc
Posts: 56
Joined: 25 May 2019, 03:11

Re: only white in specified area ?

Post by jsjcjsjc » 28 Jan 2023, 21:06

wer wrote:
27 Jan 2023, 08:15
boiler wrote:
27 Jan 2023, 07:58
@wer — It would be faster and eliminate the need to check the resulting location (just check ErrorLevel) if you set the search rectangle for ImageSearch to be the same as the same as the “specified” area instead of the whole screen.

Actually, it’s necessary that you do this, otherwise ImageSearch could find the white rectangle elsewhere on the screen (higher up or to the left of it) and it would fail your location test and never move on to potentially find the desired location since it only finds the first match.
right sir, should be like:

Code: Select all

ImageSearch, up_left_x, up_left_y, x-50, y-50, x+50, y+50, totally white picture.png
my mistake, thanks for teaching
Thanks for your kind help.
I try to change your code from "The area near the mouse" to "Specified area(400,400,1000,1000)" , but it looks failed.
I tried many times , but failed.
could you please help me with it?

wer
Posts: 57
Joined: 29 Nov 2022, 21:28

Re: only white in specified area ?

Post by wer » 28 Jan 2023, 22:53

@jsjcjsjc
well, you mean:

Code: Select all

Loop
{
    sleep, 1000
    ImageSearch, up_left_x, up_left_y, 400, 400, 1000, 1000, totally white picture.png
    msgbox,,, % up_left_x " " up_left_y, 1
}
this code wont report the right "up_left_x/y" ?
i tested it, its ok
maybe you could post your whole code or describe your whole requirement
i can help you debug it or code it

jsjcjsjc
Posts: 56
Joined: 25 May 2019, 03:11

Re: only white in specified area ?

Post by jsjcjsjc » 29 Jan 2023, 01:12

wer wrote:
28 Jan 2023, 22:53
@jsjcjsjc
well, you mean:

Code: Select all

Loop
{
    sleep, 1000
    ImageSearch, up_left_x, up_left_y, 400, 400, 1000, 1000, totally white picture.png
    msgbox,,, % up_left_x " " up_left_y, 1
}
this code wont report the right "up_left_x/y" ?
i tested it, its ok
maybe you could post your whole code or describe your whole requirement
i can help you debug it or code it
my mistake, I didn't make my thoughts clear.
My problem is how to know there is only white in (400, 400, 1000, 1000), but the code below is not right, if there is another color it will still display "up_left_x " " up_left_y".

Code: Select all

f1::
mousemove,400, 400
sleep, 1000
mousemove, 1000, 1000

CoordMode, Mouse, Screen
CoordMode, Pixel, Screen
Loop
{
    sleep, 1000
    ImageSearch, up_left_x, up_left_y, 400, 400, 1000, 1000, C:\white.png
	if (ErrorLevel = 1)
    MsgBox,,, could not be found on the screen, 1
	else
    msgbox,,, % up_left_x " " up_left_y, 1
}

f5::pause  
f6::reload

jsjcjsjc
Posts: 56
Joined: 25 May 2019, 03:11

Re: only white in specified area ?

Post by jsjcjsjc » 29 Jan 2023, 01:19

oh..I should make a 600x600 white picture, then it works.

is it possible to use any size white PNG file ?

wer
Posts: 57
Joined: 29 Nov 2022, 21:28

Re: only white in specified area ?

Post by wer » 29 Jan 2023, 02:25

jsjcjsjc wrote:
29 Jan 2023, 01:19
oh..I should make a 600x600 white picture, then it works.

is it possible to use any size white PNG file ?
right bro
if you use a smaller png, we say it 300*300 maybe
then you should repeat imagesearch at least 4 times to detemine a 600*600 area whether or not whole white finally, otherwise you can not 100 precent guarantee it

Post Reply

Return to “Ask for Help (v1)”