Jump to content

Button know when it is clickable and when not with pixel


Recommended Posts

Hello there,

On the button there is image and when it is gray you cant click,
but when it is green I want click.

I taught:
get position of that button and then check with pixel if there is that color?

I would like that I'm independed of screen resolution and can take on the
class of that button and then get cordinate and go with pixelsearch.

Link to comment
Share on other sites

WinWait($listWindow, "", 30)
   $hdlWindow = WinGetHandle($listWindow)
   ;$hdlList = ControlGetHandle($hdlWindow, "", $topicsList)
   $hc = ControlGetHandle('[CLASS:TImageButton; INSTANCE:11]','','')
   $k = WinGetPos("FormResearchGR")
   ConsoleWrite($k)
   $j = ControlClick($listWindow, "", "[CLASS:TImageButton; INSTANCE:11]", "left", 1)
   ConsoleWrite($j)

But getting position of button, like coordinates, I dont get it, Maybe WinGetPos is only for window it self
and not for position of the button on the window?

I wanted to get position of the button on the window to minimize work of search on pixelsearch
So far I am

Link to comment
Share on other sites

ControlGetPos was looking at this one it should be maybe better

because this control works fine:
ControlClick($listWindow, "", "[CLASS:TImageButton; INSTANCE:11]", "left", 1)

Link to comment
Share on other sites

Ok first mistake to learn ConsoleWrite is not like in php var_dump() to show me array or object or anything.

I did with next example from helpfile:

; Run Notepad
    Run("notepad.exe")

    ; Wait 10 seconds for the Notepad window to appear.
    Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)

    ; Retrieve the position x, y and size (width and height) of the edit control in Notepad. The handle returned by WinWait is used for the "title" parameter of ControlGetPos.
    Local $aPos = ControlGetPos($hWnd, "", "Edit1")

    ; Display the position and size of the edit control.
    MsgBox($MB_SYSTEMMODAL, "", "Position: " & $aPos[0] & ", " & $aPos[1] & @CRLF & "Size: " & $aPos[2] & ", " & $aPos[3])

    ; Close the Notepad window using the handle returned by WinWait.
    WinClose($hWnd)

then I took only message that prompts me and got positions with next codes:

Local $hWnd = WinWait("[CLASS:TFormResearchGR]", "", 10)
    WinActivate($hWnd)
    $aPos = ControlGetPos($hWnd, "", "[CLASS:TImageButton; INSTANCE:11]")
   MsgBox($MB_SYSTEMMODAL, "", "Position: " & $aPos[0] & ", " & $aPos[1] & @CRLF & "Size: " & $aPos[2] & ", " & $aPos[3])
ConsoleWrite($aPos[0])

Ok so I learned one thing ConsoleWrite only give string and never array or object,
What function is it in AutoIt to get all details of array or object?

 

Ok I get the coordinates, now I will go to pixelsearch to check how that would work

Link to comment
Share on other sites

Ok final code is:
 

Local $hWnd = WinWait("[CLASS:TFormResearchGR]", "", 10)
    WinActivate($hWnd)
    $aPos = ControlGetPos($hWnd, "", "[CLASS:TImageButton; INSTANCE:11]")
   MsgBox($MB_SYSTEMMODAL, "", "Position: " & $aPos[0] & ", " & $aPos[1] & @CRLF & "Size: " & $aPos[2] & ", " & $aPos[3])
ConsoleWrite($aPos[0] & ":")
ConsoleWrite($aPos[1] & ":")
ConsoleWrite($aPos[2] & ":")
ConsoleWrite($aPos[3] & ":")
$sizeX = $aPos[0] + $aPos[2]
$sizeY = $aPos[1] + $aPos[3]
; Find a pure red pixel in the range 0,0-20,300
Local $aCoord = PixelSearch($aPos[0], $aPos[1], $sizeX, $sizeY, 0xFF546A)
If Not @error Then
    MsgBox($MB_SYSTEMMODAL, "", "X and Y are: " & $aCoord[0] & "," & $aCoord[1])
EndIf

To get color of the button, if there is color of button it will give me pixelsearch if not it will show nothing.
Code works :)

Link to comment
Share on other sites

@Daka,

Apology I wasn't able to response to you yesterday, I was off the office at that time. Anyway, I made my testing with some related code with your concern and everything is working fine (using another window) WinWait, ControlGetPos etc.... However, when attempting to check your code, I think FormResearchGP is missing in my machine and failed to response as well in my console and having error.

Hope someone here in this forum can extend their help finding your issue. But, as what I've seen and reading in you final code, I think that's fine and no issue.^_^

 

KS15

 

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

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...