Jump to content

PixelGetColor using ControlGetPos


boshi
 Share

Recommended Posts

Hello everyone, after a few month i learn about AutoIT, i found that AutoIT is interesting. I have write a script but i don't know why is it having problem. Please could anyone highlight the problem here.

$GetWin = _WinGetHandleByExe('main.exe', '287462')
$pos = ControlGetPos( $GetWin, "", "")
Hotkeyset ( "{END}", "exit1")

Func _WinGetHandleByExe($sExe, $sTitle = '', $sText = '')
    Local $aPlist = ProcessList($sExe)
    Local $aWList = WinList(), $sHold
    For $iCC = 1 To UBound($aWList, 1) - 1
        For $xCC = 1 To UBound($aPList, 1) - 1
            If WinGetProcess($aWList[$iCC][1]) = $aPList[$xCC][1] Then
                If $sTitle Then
                    If StringInStr($aWList[$iCC][0], $sTitle) Then
                        Return $aWList[$iCC][1]
                    EndIf
                ElseIf $sText Then
                    If StringInStr(WinGetText($aWList[$iCC][0]), $sText) Then
                        Return $aWList[$iCC][1]
                    EndIf
                Else
                    If BitAND(WinGetState($aWList[$iCC][1]), 2) Then Return $aWList[$iCC][1]
                EndIf
            EndIf
        Next
    Next
    Return SetError(1, 0, '')
EndFunc

While 1 = 1
    
If PixelGetColor ( $pos[0]+150, $pos[1]+528 ) = 0x201038 then topup()
    
WEnd

Func topup()
    If PixelGetColor ( $pos[0]+657, $pos[1]+564 ) < 16317688 then 
    ControlClick ( $GetWin, "", "", "left", 3, $pos[0]+700, $pos[1]+505 ) ;bag
    ControlClick ( $GetWin, "", "", "left", 3, $pos[0]+596, $pos[1]+422 ) ;use
    ControlClick ( $GetWin, "", "", "left", 3, $pos[0]+712, $pos[1]+246 ) ;target
    Sleep ( 1000 )
Else
EndIf
EndFunc
    

    func exit1()
        Exit (0)
    endfunc

Also i need the speed to be slower. Thanx in advance

Edited by boshi
Link to comment
Share on other sites

NOT TESTED....

Opt("GUICoordMode", 2)          ;1=absolute, 0=relative, 2=cell
Opt("MouseCoordMode", 2)        ;1=absolute, 0=relative, 2=client
Opt("MouseClickDelay", 100)      ;10 milliseconds

HotKeySet("{END}", "exit1")

Global $GetWin = _WinGetHandleByExe('main.exe', '287462')
Global $pos = ControlGetPos($GetWin, "", "")


While 1

    If PixelGetColor($pos[0] + 150, $pos[1] + 528) = 0x201038 Then topup()
    Sleep(100) ; this *loop has to have a sleep, you can make it larger
WEnd


;-------------------------Functions-----------------------

Func _WinGetHandleByExe($sExe, $sTitle = '', $sText = '')
    Local $aPlist = ProcessList($sExe)
    Local $aWList = WinList(), $sHold
    For $iCC = 1 To UBound($aWList, 1) - 1
        For $xCC = 1 To UBound($aPlist, 1) - 1
            If WinGetProcess($aWList[$iCC][1]) = $aPlist[$xCC][1] Then
                If $sTitle Then
                    If StringInStr($aWList[$iCC][0], $sTitle) Then
                        Return $aWList[$iCC][1]
                    EndIf
                ElseIf $sText Then
                    If StringInStr(WinGetText($aWList[$iCC][0]), $sText) Then
                        Return $aWList[$iCC][1]
                    EndIf
                Else
                    If BitAND(WinGetState($aWList[$iCC][1]), 2) Then Return $aWList[$iCC][1]
                EndIf
            EndIf
        Next
    Next
    Return SetError(1, 0, '')
EndFunc   ;==>_WinGetHandleByExe

Func topup()
    If PixelGetColor($pos[0] + 657, $pos[1] + 564) < 16317688 Then
        ControlClick($GetWin, "", "", "left", 3, $pos[0] + 700, $pos[1] + 505) ;bag
        ControlClick($GetWin, "", "", "left", 3, $pos[0] + 596, $pos[1] + 422) ;use
        ControlClick($GetWin, "", "", "left", 3, $pos[0] + 712, $pos[1] + 246) ;target
        Sleep(1000); the sleep should not be here, it should be in the *loop
    EndIf
EndFunc   ;==>topup

Func exit1()
    Exit (0)
EndFunc   ;==>exit1

ControlGetPos($GetWin, "", "") ; needs a control #. You get it with the Autoit Window Info Tool. press Start> Autoit v3> Autoit Window Info

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

  • Moderators

_WinGetHandleByEx ;)

Ya'll are missing Opt("PixelCoordMode", 2), remember that the control position is within the "client" area. All coords should be client position coords that you use.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

_WinGetHandleByEx ;)

Ya'll are missing Opt("PixelCoordMode", 2), remember that the control position is within the "client" area. All coords should be client position coords that you use.

Yes _WinGetHandleByEx() by SmOke_N himself!!!

I was getting all the crap straightened out and noticed that too....

8)

NEWHeader1.png

Link to comment
Share on other sites

;) yay! thank you SmOke_N for the very useful function. Really like it!! :D

Oic. The ControlGetPos is ok i think Valuater because it detect my client. The problem is to get the position of the pixel.

And now I got an idea. Thanx to Valuater and SmOke_N for the solution.

Opt ("PixelCoordMode") is the same with Opt ("MouseCoordMode") ? I think this is the solution Thankyou everyone ;)

If i use Opt ("PixelCoordMode", 2) I don't need to use ControlGetPos function?

And also

If PixelGetColor ( $pos[0]+657, $pos[1]+564 ) < 16317688 then

delete the $pos[0]+ and $pos[1]+ ?

Edited by boshi
Link to comment
Share on other sites

I am afraid that PixelGetColor function cannot be used when I am using WinGetHandleByExe function..

The script detect the client and the script work fine when my client at coordinate (1,1) but when i move the window, the pixelgetcolor function didnt work ;)

Edited by boshi
Link to comment
Share on other sites

Here is the script. A lilttle bit different but the concept is still the same.. Thank you in advance

$GetWin = _WinGetHandleByExe('main.exe', '247622')
$Topup = 0
$x = 500
$y = 260
Opt("GUICoordMode", 2)          ;1=absolute, 0=relative, 2=cell
Opt("MouseCoordMode", 2)        ;1=absolute, 0=relative, 2=client
Opt("MouseClickDelay", 500)      ;10 milliseconds
    Hotkeyset ( "{END}", "exit1")

while 1 = 1
If PixelGetColor ( 153, 528 ) = 0x201038 then topup()
If $x = 740 then $x = 500
wend

;-------------------Functions-------------------------

Func _WinGetHandleByExe($sExe, $sTitle = '', $sText = '')
    Local $aPlist = ProcessList($sExe)
    Local $aWList = WinList(), $sHold
    For $iCC = 1 To UBound($aWList, 1) - 1
        For $xCC = 1 To UBound($aPList, 1) - 1
            If WinGetProcess($aWList[$iCC][1]) = $aPList[$xCC][1] Then
                If $sTitle Then
                    If StringInStr($aWList[$iCC][0], $sTitle) Then
                        Return $aWList[$iCC][1]
                    EndIf
                ElseIf $sText Then
                    If StringInStr(WinGetText($aWList[$iCC][0]), $sText) Then
                        Return $aWList[$iCC][1]
                    EndIf
                Else
                    If BitAND(WinGetState($aWList[$iCC][1]), 2) Then Return $aWList[$iCC][1]
                EndIf
            EndIf
        Next
    Next
    Return SetError(1, 0, '')
EndFunc;==> _WinGetHandleByExe

Func Topup()

If PixelGetColor ( 657, 564 ) < 16317688 then 
    

    ControlClick ( $GetWin, "", "", "left", 1, 701, 506 ) ;bag
    
    ControlClick ( $GetWin, "", "", "left", 1, $x, $y ) ;pear
    
    ControlClick ( $GetWin, "", "", "left", 3, 597, 423 ) ;use

    ControlClick ( $GetWin, "", "", "left", 2, 719, 233 ) ;target
    
    $x = $x + 40
Else 
EndIf
endfunc ;==> Topup




    func exit1()
        Exit (0)
    endfunc;==> exit1

Omg why no one reply?? ;)

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