Sign in to follow this  
Followers 0
Feonixx

PixelSearch()

5 posts in this topic

; Script Start - Add your code below here

#Include <GUIConstants.au3>
#Include <Misc.au3>
#include <EditConstants.au3>

Global $nCont = 0, $xColor = 0x000000, $iRunning = False
MsgBox(0,"ColorPicker/Chooser","Made By: Feonix")

$main = GUICreate("Color Picker",150,50)
$Button1 = GUICtrlCreateButton("Color Picker",25,15,100,20)

$main2 = GUICreate("Color Picker",150,300)
$Button2 = GUICtrlCreateButton("Back to Main",25,20,100,20)
$Label1 = GUICtrlCreateLabel("",50,100,50,50)
$Button3 = GUICtrlCreateButton("Choose your color",25,200,100,20)
$hHex = GUICtrlCreateInput("", 25, 50, 100, -1, $ES_READONLY)
$Button4 = GUICtrlCreateButton("Start- Move away from screen",1,250,150,20)
WinSetOnTop($main2, "",1)

GUISetState(@SW_SHOW, $main)

While 1
    $msg = GUIGetMsg()
        Select
            Case $msg = $Button1
                GUISetState(@SW_HIDE, $main)
                Sleep(100)
                GUISetState(@SW_SHOW, $main2)
            Case $msg = $Button2
                GUISetState(@SW_HIDE, $main2)
                GUISetState(@SW_SHOW, $main)
            Case $msg = $GUI_EVENT_CLOSE
                Exit
            Case $msg = $Button3
                Do  
                    If PixelGetColor(MouseGetPos(0), MouseGetPos(1)) <> $xColor Then
                    $xColor = PixelGetColor(MouseGetPos(0), MouseGetPos(1))
                    GUICtrlSetBkColor($Label1, $xColor)
                    GUICtrlSetBkColor($hHex, $xColor)
                    GUICtrlSetData($hHex, "0x" & StringRight(Hex($xColor), 6))
                    EndIf
                Until _IsPressed(01)
            Case $msg = $Button4
                $coord = PixelSearch(10, 10, 800, 580, $hHex)
                If IsArray($coord) = 1 Then
                MouseClick('left', $coord[0], $coord[1], 1, 0)
                EndIf
        EndSelect
WEnd

Kk, so its doing all i want it to so far, it has a main window, opens into another, and finds a color (just load to see). Now, i want it to take the hex value in the input box and search for it, and then move to it and click. Thats where its messing up and not doing it, could these be a problem with the @ES_READONLY, or something else? Thanks for any help muttley

Share this post


Link to post
Share on other sites



bump

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

$hHex is only a controlID, you need to use GUICtrlRead($hHex) for reading the value from the input!

So set like

$DataRead = GUICtrlRead($hHex)

And then set that to the one its reading and the value to search for?

EDIT:

#Include <GUIConstants.au3>
#Include <Misc.au3>
#include <EditConstants.au3>

Global $nCont = 0, $xColor = 0x000000, $iRunning = False
MsgBox(0,"Main Window","Made By: Feonix")

$main = GUICreate("Window",150,50)
$Button1 = GUICtrlCreateButton("Open another window",25,15,100,20)

$main2 = GUICreate("Window",150,300)
$Button2 = GUICtrlCreateButton("Back to Main",25,20,100,20)
$Label1 = GUICtrlCreateLabel("",50,100,50,50)
$Button3 = GUICtrlCreateButton("Choose your color",25,200,100,20)
$hHex = GUICtrlCreateInput("", 25, 50, 100, -1, $ES_READONLY)
$Button4 = GUICtrlCreateButton("Start- Move away from screen",1,250,150,20)
WinSetOnTop($main2, "Yay",1)

GUISetState(@SW_SHOW, $main)

$DataRead = GUICtrlRead($hHex)

While 1
    $msg = GUIGetMsg()
        Select
            Case $msg = $Button1
                GUISetState(@SW_HIDE, $main)
                Sleep(100)
                GUISetState(@SW_SHOW, $main2)
            Case $msg = $Button2
                GUISetState(@SW_HIDE, $main2)
                GUISetState(@SW_SHOW, $main)
            Case $msg = $GUI_EVENT_CLOSE
                Exit
            Case $msg = $Button3
                Do  
                    If PixelGetColor(MouseGetPos(0), MouseGetPos(1)) <> $xColor Then
                    $xColor = PixelGetColor(MouseGetPos(0), MouseGetPos(1))
                    GUICtrlSetBkColor($Label1, $xColor)
                    GUICtrlSetBkColor($hHex, $xColor)
                    GUICtrlSetData($hHex, "0x" & StringRight(Hex($xColor), 6))
                    EndIf
                Until _IsPressed(01)
            Case $msg = $Button4
                $coord = PixelSearch(10, 10, 800, 580, $DataRead)
                If IsArray($coord) = 1 Then
                MouseClick('left', $coord[0], $coord[1], 1, 0)
                EndIf
        EndSelect
WEnd

Changed to this, and the mouse moves, but it doesnt move to the color, just to the corner of the screen

Edited by Feonixx

Share this post


Link to post
Share on other sites

You are "reading" the value when the input doesn't have anything in it and therefore your code doesn't work as intended. For that to work you need to move your GUICtrlRead() to right after GUICtrlSetData() or directly in PixelSearch()

I also just noticed your input was read-only so the easiest in this case would be to put $xColor in your PixelSearch() so you don't need any GUICtrlRead()

For example:

#Include <GUIConstantsEx.au3>
#Include <Misc.au3>
#include <EditConstants.au3>

Global $nCont = 0, $xColor = 0x000000, $iRunning = False
MsgBox(0,"Main Window","Made By: Feonix")

$main = GUICreate("Window",150,50)
$Button1 = GUICtrlCreateButton("Open another window",15,15,120,20)

$main2 = GUICreate("Window",150,300)
$Button2 = GUICtrlCreateButton("Back to Main",25,20,100,20)
$Label1 = GUICtrlCreateLabel("",50,100,50,50)
$Button3 = GUICtrlCreateButton("Choose your color",25,200,100,20)
$hHex = GUICtrlCreateInput("", 25, 50, 100, -1, $ES_READONLY)
$Button4 = GUICtrlCreateButton("Start- Move away from screen",1,250,150,20)
WinSetOnTop($main2, "Yay",1)

GUISetState(@SW_SHOW, $main)

While 1
    $msg = GUIGetMsg()
        Select
            Case $msg = $Button1
                GUISetState(@SW_HIDE, $main)
                Sleep(100)
                GUISetState(@SW_SHOW, $main2)
            Case $msg = $Button2
                GUISetState(@SW_HIDE, $main2)
                GUISetState(@SW_SHOW, $main)
            Case $msg = $GUI_EVENT_CLOSE
                Exit
            Case $msg = $Button3
                Do  
                    If PixelGetColor(MouseGetPos(0), MouseGetPos(1)) <> $xColor Then
                    $xColor = PixelGetColor(MouseGetPos(0), MouseGetPos(1))
                    GUICtrlSetBkColor($Label1, $xColor)
                    GUICtrlSetBkColor($hHex, $xColor)
                    GUICtrlSetData($hHex, "0x" & StringRight(Hex($xColor), 6))
                    EndIf
                Until _IsPressed(01)
            Case $msg = $Button4
                $coord = PixelSearch(10, 10, 800, 580, $xColor)
                If IsArray($coord) = 1 Then
                MouseClick('left', $coord[0], $coord[1], 1, 0)
                EndIf
        EndSelect
WEnd

Do note that I also increased the width on $Button1 because I couldn't see all of the outmost letters and i changed

#Include <GUIConstants.au3>

to

#Include <GUIConstantsEx.au3>

Because I am using the newest stable AutoIt (3.2.12.1)

Share this post


Link to post
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
Sign in to follow this  
Followers 0