Sign in to follow this  
Followers 0
Daka

Button know when it is clickable and when not with pixel

13 posts in this topic

#1 ·  Posted

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.

Share this post


Link to post
Share on other sites



#2 ·  Posted

@Daka,

What have you got so far?

Share this post


Link to post
Share on other sites

#3 ·  Posted

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

Share this post


Link to post
Share on other sites

#4 ·  Posted

Can you provide the $listWindow?.

Share this post


Link to post
Share on other sites

#5 ·  Posted

$listWindow = "[CLASS:TFormResearchGR]"

Share this post


Link to post
Share on other sites

#6 ·  Posted

ControlGetPos was looking at this one it should be maybe better

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

Share this post


Link to post
Share on other sites

#7 ·  Posted

Local $hWnd = WinWait("[CLASS:TFormResearchGR]", "", 10)
    WinActivate($hWnd)
    $pos = ControlGetPos("FormResearchGR", "", "[CLASS:TImageButton; INSTANCE:11]")
   ConsoleWrite($pos)

$pos dont give me anything :(

Share this post


Link to post
Share on other sites

#8 ·  Posted

this is the info of the window and that button

Screen Shot 2017-06-22 at 1.08.45 PM.png

Share this post


Link to post
Share on other sites

#9 ·  Posted

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

Share this post


Link to post
Share on other sites

#10 ·  Posted

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 :)

Share this post


Link to post
Share on other sites

#11 ·  Posted

@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

 

Share this post


Link to post
Share on other sites

#12 ·  Posted

yes it code is working great :)

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