Sign in to follow this  
Followers 0
yarz

Mouse move to colour

6 posts in this topic

Hello all,

I want to make a script that searches for a colour, moves the mouse to that colour and then clicks it.

This is what I have, but it is not working..:

CODE
; Get the color to match (change this to suit).

sleep(10000)

$iColor = 0x00FF00

Dim $Coord[2]

While IsArray($Coord)

$Coord = PixelSearch(1204, 566, 1414, 627, $iColor)

If @error = 0 then

; The color was found

MouseMove($Coord)

MouseClick("left")

Sleep(5000)

; A debug message that lasts only one second

MsgBox(4096, "Debug", "Mouse Left Click done.", 1)

EndIf

WEnd

MsgBox(4096, "Debug", "While loop has terminated")

My idea was, it searches the pixelcoordinates and saves it in $Coord, then it moves the mouse to $Coord, but that's not working.

I've just started with AutoIt so this is maybe a newb question, but can anyone help me out?

Thanks

Share this post


Link to post
Share on other sites



These numbers are way-off my screen

$Coord = PixelSearch(1204, 566, 1414, 627, $iColor)

PixelSearch ( left, top, right, bottom, color )

and look ay MouseMove() again, it needs two coordinates

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

These numbers are way-off my screen

$Coord = PixelSearch(1204, 566, 1414, 627, $iColor)

PixelSearch ( left, top, right, bottom, color )

and look ay MouseMove() again, it needs two coordinates

8)

Well, I have a 24" screen so that can be right..

I want to move the mouse to the colour, but that place can be in 4 different positions, so i can't give the coordinates as a number..

Share this post


Link to post
Share on other sites

this is how it would be used..

; Get the color to match (change this to suit).
Sleep(10000)
$iColor = 0x00FF00

Dim $Coord[2]
While IsArray($Coord)
    $Coord = PixelSearch(1204, 566, 1414, 627, $iColor)
    If @error = 0 Then
        ; The color was found
        MouseMove($Coord[0], $Coord[1])
        MouseClick("left")
        Sleep(5000)
        ; A debug message that lasts only one second
        MsgBox(4096, "Debug", "Mouse Left Click done.", 1)
    EndIf
WEnd
MsgBox(4096, "Debug", "While loop has terminated")

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Dim $icolor,$timer,$Coord[2]
; Get the color to match (change this to suit).
sleep(10000)
$iColor = 0x00FF00
$timer=Timerinit()

Do
Do
$Coord = PixelSearch(1204, 566, 1414, 627, $iColor)
Until IsArray($Coord) or Timerdiff($timer)>10000
If IsArray($Coord) Then
MouseMove($Coord[0],$coord[1])
MouseClick("left")
sleep(5000)
Endif
Until @error<>0

This would work i guess. I always prefer this so you can even state how long the search should be.

Edited by cageman

Share this post


Link to post
Share on other sites

Thanks! I didn't know about the numbers.

Now I want that AutoIt refreshes the page when the result is negative so i've this:

CODE
; Get the color to match (change this to suit).

Sleep(10000)

$iColor = 0x00FF00

Dim $Coord[2]

While IsArray($Coord)

$Coord = PixelSearch(1204, 566, 1414, 627, $iColor)

If @error = 0 Then

; The color was found

MouseMove($Coord[0], $Coord[1])

MouseClick("left")

Sleep(10000)

; A debug message that lasts only one second

MsgBox(4096, "Debug", "Mouse Left Click done.", 1)

EndIf

If @error = 1 Then

Sleep(Random(8000, 14000))

Send('{f5}')

SetError(0)

EndIf

WEnd

MsgBox(4096, "Debug", "While loop has terminated")

But I think there is something wrong with the loop, but I'm still figuring out what

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