Jump to content

PixelSearch and then MouseClick?


Recommended Posts

Hello. I'm trying to make it detect a color and then click it. Always searching for it, and click on it on when it pops up.

$Loop = 0
    While $Loop = 0
    If $SearchResult = PixelSearch ($Hoejre, $Toppen, $Venstre, $Bunden, $Farve) Then Mouseclick ("Primary", $SearchResult, $SearchResult, 10, 0)
    Sleep(1000)
    If $Loop = 1 Then ContinueLoop
WEnd

What's wrong with that code? It never clicks the color when it pops up. :whistle:

Link to comment
Share on other sites

Hello. I'm trying to make it detect a color and then click it. Always searching for it, and click on it on when it pops up.

$Loop = 0
    While $Loop = 0
    If $SearchResult = PixelSearch ($Hoejre, $Toppen, $Venstre, $Bunden, $Farve) Then Mouseclick ("Primary", $SearchResult, $SearchResult, 10, 0)
    Sleep(1000)
    If $Loop = 1 Then ContinueLoop
WEnd

What's wrong with that code? It never clicks the color when it pops up. :lmao:

Read the help file. PixelSearch() returns an array, which will be $SearchResult. If you try to make a numeric compare with an entire array it is always 0, so your If statement is never true. Try:

While 1
    $SearchResult = PixelSearch ($Hoejre, $Toppen, $Venstre, $Bunden, $Farve)
    If Not @error Then Mouseclick ("Primary", $SearchResult[0], $SearchResult[1], 10, 0)
    Sleep(20); avoid spiking CPU
WEnd

:whistle:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Read the help file. PixelSearch() returns an array, which will be $SearchResult. If you try to make a numeric compare with an entire array it is always 0, so your If statement is never true. Try:

While 1
    $SearchResult = PixelSearch ($Hoejre, $Toppen, $Venstre, $Bunden, $Farve)
    If Not @error Then Mouseclick ("Primary", $SearchResult[0], $SearchResult[1], 10, 0)
    Sleep(20); avoid spiking CPU
WEnd

:)

Still didnt change anything, still didnt click? :s
Link to comment
Share on other sites

Still didnt change anything, still didnt click? :s

Works fine for me, what are you using for inputs...?

Dim $Hoejre = 0, $Toppen = 0, $Venstre = 50, $Bunden = 50, $Farve = 0xFFFFFF

HotKeySet("{ESC}", "_Quit")

While 1
    $SearchResult = PixelSearch($Hoejre, $Toppen, $Venstre, $Bunden, $Farve)
    If Not @error Then MouseClick("Primary", $SearchResult[0], $SearchResult[1], 10, 0)
    Sleep(20); avoid spiking CPU
WEnd

Func _Quit()
    Exit
EndFunc   ;==>_Quit

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

The input variables:

$Farve = 0xFFCC66
$Hoejre = 406
$Toppen = 21
$Venstre = 30
$Bunden = 372

Ill add a picture of the situation:

Posted Image

You have confused the coordinates. Re-read the help file on PixelSearch() and look at the order you are giving the coordinates. The first two parameters are X,Y of the top/left (that would be your AutoIt-left) corner of the search box. The next two parameters are the X'/Y' of the bottom/right corner. Your numbers don't make sense.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...