Jump to content

PixelGetColor - checking for multiple values


Recommended Posts

If GUICtrlRead($checkbox) = $GUI_CHECKED And Not (PixelGetColor(GUICtrlRead($value1x), GUICtrlRead($value1y)) = (GUICtrlRead($testcolor1))) And Not (PixelGetColor(GUICtrlRead($value1x), GUICtrlRead($value1y)) = (GUICtrlRead($testcolor2))) And Not (PixelGetColor(GUICtrlRead($value1x), GUICtrlRead($value1y)) = (GUICtrlRead($testcolor3))) Then
            dothething()
        EndIf

Trying to make sure a color in the assigned pixel location is not one of the 3 color values. The way I'm doing it works.. but is there a cleaner way?

 

Thanks.

Edited by dustinisgod
Link to comment
Share on other sites

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 112, 32, 75, 25);button
$Button2 = GUICtrlCreateButton("Button1", 112, 32, 75, 25);button
$Input1= GUICtrlCreateInput("testcolor1", 56, 64, 121, 21);testcolor1
$Input2 = GUICtrlCreateInput("testcolor2", 56, 64, 121, 21);testcolor2
$Input3 = GUICtrlCreateInput("testcolor3", 56, 64, 121, 21);testcolor3
$value1x = GUICtrlCreateInput("", 56, 64, 121, 21);value1x
$value1y = GUICtrlCreateInput("", 56, 64, 121, 21);value1y
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $Button1
For $i = 1 To 3 Step 1;;check every testcolor 1 2 3
   If GUICtrlRead($checkbox) = $GUI_CHECKED And Not (PixelGetColor(GUICtrlRead($value1x), GUICtrlRead($value1y)) = (ControlGetText("Form1","","Edit"&$i)))
              dothething()
        EndIf
            Next
    EndSwitch
WEnd

 

Edited by ad777

iam ِAutoit programmer.

best thing in life is to use your Brain to

Achieve

everything you want.

Link to comment
Share on other sites

9 hours ago, markyrocks said:

Shoving a couple more function calls in there might clean it up a bit.  I saw a little bit of white space in there that could use filling. 

I am assuming this is snark? Unfortunately, I have zero programming experience, and am self teaching myself this stuff and my coding skills are below basic at the moment. Hopefully, I will be better with time.

Link to comment
Share on other sites

23 hours ago, ad777 said:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 112, 32, 75, 25);button
$Button2 = GUICtrlCreateButton("Button1", 112, 32, 75, 25);button
$Input1= GUICtrlCreateInput("testcolor1", 56, 64, 121, 21);testcolor1
$Input2 = GUICtrlCreateInput("testcolor2", 56, 64, 121, 21);testcolor2
$Input3 = GUICtrlCreateInput("testcolor3", 56, 64, 121, 21);testcolor3
$value1x = GUICtrlCreateInput("", 56, 64, 121, 21);value1x
$value1y = GUICtrlCreateInput("", 56, 64, 121, 21);value1y
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $Button1
For $i = 1 To 3 Step 1;;check every testcolor 1 2 3
   If GUICtrlRead($checkbox) = $GUI_CHECKED And Not (PixelGetColor(GUICtrlRead($value1x), GUICtrlRead($value1y)) = (ControlGetText("Form1","","Edit"&$i)))
              dothething()
        EndIf
            Next
    EndSwitch
WEnd

 

 

For $i = 1 To 3 Step 1

Thanks for the help. I looked up this bit of code on the help section. And I kind of understand it. What I do not understand is how does it know that $Input1,2,3 are the variables that it should be reading?

(ControlGetText("Form1","","Edit"&$i)))

Update: I think I have figure out what this means.. so where It says Edit.. If this is changed to $Input1.. the code starts at input 1 in the form1.. then steps 1 down to the next line which would be input 2.. then steps again to the 3rd which is input3. Am I understanding this correctly?

Edited by dustinisgod
Link to comment
Share on other sites

Ok then, are you sure you cannot read those numbers directly from the application instead of trying to read the pixels ?  Can you tell us a bit more about the application (is it a windows app or web app) ?  Have you tried to use au3info tool over the fields ?

Overall, using pixel* functions is probably the worst way to automate an application.  Make sure you eliminate all robust approach before reverting to pixel !

Edited by Nine
Link to comment
Share on other sites

14 hours ago, dustinisgod said:

I am assuming this is snark? Unfortunately, I have zero programming experience, and am self teaching myself this stuff and my coding skills are below basic at the moment. Hopefully, I will be better with time.

You will get better.  I was joking.   But the truth is if your code looks like that set a variable equal to the function. When started out it took me a minute to get this concept aswell.  When a function returns a value regardless doing something like $retVal=func()  will set the variable to whatever that value is.  Then you don't have to keep calling that function to get the value bc you can just use your variable instead.   In your case it will make your code alot more readable.   When I look at the first post it makes my eyes water.  But keep at it.  Good luck. 

 

Edit also reducing function calls makes your script faster. Efficiency is king.

Edited by markyrocks
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...