Jump to content

Recommended Posts

Posted

This example appears to be working ok.
The mouse stops moving when they are no 0x50BA0F coloured pixels to right on the same line nor below the stopped mouse pointer.

Press the Esc button to exit at any time.

Opt("WinTitleMatchMode", -2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Opt("PixelCoordMode", 2) ;1=absolute, 0=relative, 2=client
Opt("MouseCoordMode", 2) ;1=absolute, 0=relative, 2=client

HotKeySet("{ESC}", "Terminate") ; Press Esc to exit

ShellExecute("circles.jpg") ; Image is in same directory as script, otherwise, use full path name of image file.
Local $hWin = WinWaitActive("circle", "")
Sleep(1000)
Local $aWinPos = WinGetPos("circle", "")
Local $aCtrlPos = ControlGetPos("circle", "", "")
;ConsoleWrite($aCtrlPos[0] & ", " & $aCtrlPos[1] & ", " & $aCtrlPos[2] & ", " & $aCtrlPos[3] & @LF)
;ConsoleWrite($aWinPos[2] & " " & $aWinPos[3] & @LF)
Local $x, $y, $a = PixelSearch(0, 0, $aWinPos[2], $aWinPos[3], "0x50BA0F", 0, 1, $hWin)
If @error Then
    Exit ; Colour does not exit in image, so exit.
Else
    $x = $a[0]
    $y = $a[1]
EndIf
;ConsoleWrite($aWinPos[3] + $aWinPos[1] & @LF)
;$y = $aCtrlPos[3]*0.95  ; For testing near end of image.

While ($y <= $aCtrlPos[3])
    $a = PixelSearch($x, $y, $aWinPos[2], $y, "0x50BA0F", 0, 1, $hWin) ; Searching one horizontal line at a time.
    If @error Then ;If colour not found, start at the beginning of a new, next line.
        $y += 1
        $x = 0
    Else
        MouseMove($x, $y, 0)
        $x = $a[0] + 1
    EndIf
    ;ConsoleWrite("Mouse Position: " & $x & ", " & $y & @CRLF)
    Sleep(10)
WEnd


Func Terminate()
    Exit
EndFunc   ;==>Terminate

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
×
×
  • Create New...