Jump to content

Exclude from previous answer?


 Share

Recommended Posts

I was just wondering if someone could help me try to find out a way to exclude previous answers from an earlier function. As you can see in my example, what I'm trying to do is find the color 25,25,25 in a mixed color palette, several times, each time giving me a different coordinate response by excluding the previous answer. I've been looking at the autoit function list sitting here trying to find something that will work.

#include <MsgBoxConstants.au3>
#include <Misc.au3>

Global $State = 0

PixelFind()

Func PixelFind()

        While $State = 0
        If _IsPressed("31") Then $State = 1 ;1
        If _IsPressed("32") Then $State = 2 ; 2
        If _IsPressed("1b") Then Exit ; ESC

    While $State = 1
        Local $aCoord = PixelSearch(0, 0, 1920, 1080, 0x191919)
        If @error then
            MsgBox($MB_SYSTEMMODAL, "Error", "An Error has occurred", 10)
                Else
                    mousemove ($aCoord[0], $aCoord[1])
                        $State = 0
        EndIf
    WEnd
    While $State = 2
        Local $aCoord = PixelSearch(0, 0, 1920, 1080, 0x191919)
            If @error then
                MsgBox($MB_SYSTEMMODAL, "Error", "An Error has occurred", 10) ;add as msgboxfunc reference func
                    Else
                        mousemove ($aCoord[0], $aCoord[1])
                            $State = 0
            EndIf
    WEnd
WEnd
EndFunc

 

Link to comment
Share on other sites

use the x,y you set in mousemove as your next starting point, something like (or maybe $x +1 , $y  + 1) idk seems logical:

$x = 0
$y = 0

Func PixelFind()

        While $State = 0
        If _IsPressed("31") Then $State = 1 ;1
        If _IsPressed("32") Then $State = 2 ; 2
        If _IsPressed("1b") Then Exit ; ESC

    While $State = 1
        Local $aCoord = PixelSearch($x, $y, 1920, 1080, 0x191919)
        If @error then
            MsgBox($MB_SYSTEMMODAL, "Error", "An Error has occurred", 10)
        Else
            $x = $aCoord[0]
            $y = $aCoord[1]
                    mousemove ( $x , $y )
                        $State = 0
        EndIf
    WEnd
    
    .....

 

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

1 minute ago, iamtheky said:

use the x,y you set in mousemove as your next starting point, something like:

$x = 0
$y = 0

Func PixelFind()

        While $State = 0
        If _IsPressed("31") Then $State = 1 ;1
        If _IsPressed("32") Then $State = 2 ; 2
        If _IsPressed("1b") Then Exit ; ESC

    While $State = 1
        Local $aCoord = PixelSearch($x, $y, 1920, 1080, 0x191919)
        If @error then
            MsgBox($MB_SYSTEMMODAL, "Error", "An Error has occurred", 10)
        Else
            $x = $aCoord[0]
            $y = $aCoord[1]
                    mousemove ( $x , $y )
                        $State = 0
        EndIf
    WEnd
    
    .....

 

ohhhhhh, thank you very much, you rock dude.

Link to comment
Share on other sites

if anyone is still interested in the topic, here's the solution:

#include <MsgBoxConstants.au3>
#include <Misc.au3>

Global $State = 0

PixelFind()

$x = 0
$y = 0

Func PixelFind()

        While $State = 0
        If _IsPressed("31") Then $State = 1 ;1
        If _IsPressed("32") Then $State = 2 ; 2
        If _IsPressed("1b") Then Exit ; ESC

    While $State = 1
        Local $aCoord = PixelSearch(0, 0, 1920, 1080, 0x191919)
        If @error then
            MsgBox($MB_SYSTEMMODAL, "Error", "An Error has occurred", 10)
        Else
            $x = $aCoord[0]
            $y = $aCoord[1]
                    mousemove ( $x , $y )
                        $State = 0
        EndIf
    WEnd
    While $State = 2
        Local $aCoord = PixelSearch(0, 0, 1920, 1080, 0x191919)
            If @error then
                MsgBox($MB_SYSTEMMODAL, "Error", "An Error has occurred", 10) ;add as msgboxfunc reference func
            Else
                $x = $aCoord[0] + 1
                $y = $aCoord[1] + 1
                    mousemove ( $x , $y )
                        $State = 0
            EndIf
    WEnd
WEnd
EndFunc

 

Edited by HankHell
Link to comment
Share on other sites

you need to put $x +1 and $y +1 on your pixelsearch, not your mousemove.  (if i understand the intent)

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

and what doesnt work?  place that command in a consolewrite or msgbox command and see what x and y are prior to them being executed in the pixelsearch. 

Im just guessing now that you wish to run in perpetuity so $x and $y would need to be reset when pixelsearch completed with no return.  Instead of msgbox "an error has occured" - maybe resetting the variables to 0, 0 and restarting the loop would create a behavior that is more desired than saying an error had occured simply because the color was not found...

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

20 minutes ago, iamtheky said:

and what doesnt work?  place that command in a consolewrite or msgbox command and see what x and y are prior to them being executed in the pixelsearch. 

Im just guessing now that you wish to run in perpetuity so $x and $y would need to be reset when pixelsearch completed with no return.  Instead of msgbox "an error has occured" - maybe resetting the variables to 0, 0 and restarting the loop would create a behavior that is more desired than saying an error had occured simply because the color was not found...

x and y variables will change every time I move the window or open another instance, so I won't be able to set static variables for it, I'd have to set the coordinates every time. PixelSearch won't accept $x and $y, even though they are set to 0. It just ends the program without searching for any pixel. I want the msgbox to open when a pixel is not found so I have notice that the color isn't in the current palette. I can change the text though.

Link to comment
Share on other sites

it works fine with variables, and since you appear to be searching the entire space from @ desktopwidth to @ desktopheight then your windows dont matter nor the dynamic-ness of your variables.  

what if under pixelsearch($x+1, $y, 1920 , 1080) you said if @error then run pixelsearch(0,0,$x,$y)  and tested that return to make sure its not the same $x and $y before resetting them? 

 

 

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

39 minutes ago, iamtheky said:

it works fine with variables, and since you appear to be searching the entire space from @ desktopwidth to @ desktopheight then your windows dont matter nor the dynamic-ness of your variables.  

what if under pixelsearch($x+1, $y, 1920 , 1080) you said if @error then run pixelsearch(0,0,$x,$y)  and tested that return to make sure its not the same $x and $y before resetting them? 

 

 

well, console says

"D:\phrm\etc\colorpixel.au3" (39) : ==> Subscript used on non-accessible variable.:
$x = $aCoord[0]
$x = $aCoord^ ERROR

#include <MsgBoxConstants.au3>
#include <Misc.au3>

Global $State = 0
Global $ColorSet = 0x191919

Global $x = 0
Global $y = 0

PixelFind()

Func PixelFind()

        While $State = 0
        If _IsPressed("31") Then $State = 1 ; 1
        If _IsPressed("32") Then $State = 2 ; 2
        If _IsPressed("33") Then $State = 3 ; 3
        If _IsPressed("34") Then $State = 4 ; 4
        If _IsPressed("1b") Then Exit ; ESC

    While $State = 1
        Local $aCoord = PixelSearch($x, $y, 1920, 1080, $ColorSet)
        If @error then
            MsgBox($MB_SYSTEMMODAL, "Error", "An Error has occurred", 10) ;add as msgboxfunc reference func
        Else
            $x = $aCoord[0]
            $y = $aCoord[1]
                mousemove ( $x , $y )
                    $State = 0
        EndIf
    WEnd
    While $State = 2
        ConsoleWrite ( $x & $y & @CRLF )
        Local $aCoord = PixelSearch($x+1, $y+1, 1920, 1080, $ColorSet)
        ConsoleWrite ( $x & $y & @CRLF )
        If @error then
            MsgBox($MB_SYSTEMMODAL, "Error", "An Error has occurred", 10)
        Else
            $x = $aCoord[0]
            $y = $aCoord[1]
                mousemove ( $x , $y )
                    $State = 0
        EndIf
    WEnd
    While $State = 3
        Local $aCoord = PixelSearch(0, 0, 1920, 1080, $ColorSet)
        If @error then
            MsgBox($MB_SYSTEMMODAL, "Error", "An Error has occurred", 10)
        Else
            $x = $aCoord[0]
            $y = $aCoord[1]
                mousemove ( $x , $y )
                    $State = 0
        EndIf
    WEnd
    While $State = 4
        Local $aCoord = PixelSearch(0, 0, 1920, 1080, $ColorSet)
        If @error then
            MsgBox($MB_SYSTEMMODAL, "Error", "An Error has occurred", 10)
        Else
            $x = $aCoord[0]
            $y = $aCoord[1]
                mousemove ( $x , $y )
                    $State = 0
        EndIf
    WEnd
WEnd
EndFunc

 

Edited by HankHell
Link to comment
Share on other sites

6 hours ago, iamtheky said:

it works fine with variables, and since you appear to be searching the entire space from @ desktopwidth to @ desktopheight then your windows dont matter nor the dynamic-ness of your variables.  

what if under pixelsearch($x+1, $y, 1920 , 1080) you said if @error then run pixelsearch(0,0,$x,$y)  and tested that return to make sure its not the same $x and $y before resetting them? 

 

 

this code just makes it keep targeting the same pixel as well. but it doesn't have any errors, however +1 seems to do nothing

 

While $State = 2
        ConsoleWrite ( $x & " " & $y & "beforesearch" & @CRLF )
        Local $aCoord = PixelSearch(0, 0, $x+1, $y+1, $ColorSet)
        ConsoleWrite ( $x & " " & $y & "aftersearch" & @CRLF )

and this code just finds the same pixel as well

While $State = 2
        $x = 0
        $y = 0
        ConsoleWrite ( $x & " " & $y & "beforesearch" & @CRLF )
        Local $aCoord = PixelSearch($x+1, $y+1, 1920, 1080, $ColorSet)
        ConsoleWrite ( $x & " " & $y & "aftersearch" & @CRLF )
        If @error then
            MsgBox($MB_SYSTEMMODAL, "Error", "Pixel Not Found", 10)
                $x = 0
                $y = 0
                $State = 0
        Else
            $x = $aCoord[0]
            $y = $aCoord[1]
                mousemove ( $x , $y )
                    $State = 0
        EndIf
    WEnd

 

Edited by HankHell
Link to comment
Share on other sites

So, Been messing with the script a little more, and ran into some weird behavior. Can someone explain this to me?

#include <MsgBoxConstants.au3>
#include <Misc.au3>

Global $State = 0

Global $ColorSet = 0x191919

Global $HorizontalWidth = 1920
Global $VerticalWidth = 1080

Global $x = 0
Global $y = 0

Dim $Mpos_1 = "", $Mpos_2 = "", $line = ""

Global $LineColor = 0x00FF00
Global $LineWidth = 4

HotKeySet("{F1}", "SetPixel")

PixelFind()

Func PixelFind()

        While $State = 0

        If _IsPressed("31") Then $State = 1 ; 1
        If _IsPressed("1b") Then Exit ; ESC

    While $State = 1

        Local $aCoord = PixelSearch(0, 0, $HorizontalWidth, $VerticalWidth, $ColorSet)
        If @error then
            MsgBox($MB_SYSTEMMODAL, "Error", "Pixel Not Found", 10) ;add as msgboxfunc reference func
                $x = 0
                $y = 0
                $State = 0
        Else
            $x = $aCoord[0]
            $y = $aCoord[1]
                mousemove ( $x , $y, 1 )
                    SetPixel()
                    $State = 0
                    $x = 0
                    $y = 0
                    $aCoord = 0
                    Sleep(100)
        EndIf
        WEnd
    WEnd
EndFunc

;----------------------------------------------------------------------------------------------------------------

Func SetPixel()

    GUICtrlDelete($line)
    $Ms_In = MouseGetPos()
    $Mpos_1 = $Ms_In[0]
    $Mpos_2 = $Ms_In[1]

    $hd = DllCall("user32.dll", "int", "GetDC", "hwnd", 0)
    $pen = DllCall("GDI32.dll", "int", "CreatePen", "int", 0, "int", $LineWidth, "int", $LineColor)
    DllCall("GDI32.dll", "int", "SelectObject", "int", $hd[0], "int", $pen[0])
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int", $Mpos_1, "int", $Mpos_2, "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $Mpos_1, "int", $Mpos_2)
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $hd[0])

EndFunc

;----------------------------------------------------------------------------------------------------------------

basically, when you press the "1" key, it'll move to the color pixel, and then cover it up with green pixels. However it doesn't find all of the pixels I'm trying to search for in $ColorSet even thoughI'm covering it up. However, it will find up to a max of 2 different pixels now...it just can't find any more than 2 $ColorSet pixels for some weird reason...

my testing includes; a white background 1920x1080 with four 25,25,25 pixels randomly on the screen surrounded by red circles.

Edited by HankHell
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...