Jump to content

Problems with Pixelsearch


Geeky
 Share

Recommended Posts

Hi, Ive made a script to search for a special color, but it wont do what i want it to do when it finds the color...

I tried to fill the whole background in paint with the color (Light Green) But it still wont react, whats the problem??

$tid = inputbox( "Checkbox tid", "How long should Checkbox run (Hours)?", "24",)
$checkbox = $tid * 6 * 60


$o = 1

$o = $o + 1

Do 

$coord = PixelSearch( 157, 170, 567, 537, 0x00ff00, 30)
$color = PixelGetColor( "$coord[0]", "$coord[1]")

If $color = ("0x00ff00") Then MouseMove ( "$coord[0]", "$coord[1]") MouseClick ("left", "$coord[0]", "$coord[1]") 



Until $o = $checkbox
Edited by Geeky
Link to comment
Share on other sites

  • Moderators

Hi, Ive made a script to search for a special color, but it wont do what i wat it to do when it finds the color...

I tried to fill the whole background in paint with the color (Light Green) But it still wont react, whats the problem??

$tid = inputbox( "Checkbox tid", "How long should Checkbox run (Hours)?", "24",)
$checkbox = $tid * 6 * 60
$o = 1

$o = $o + 1

Do 

$coord = PixelSearch( 157, 170, 567, 537, 0x00ff00, 30)
$color = PixelGetColor( "$coord[0]", "$coord[1]")

If $color = ("0x00ff00") Then MouseMove ( "$coord[0]", "$coord[1]") MouseClick ("left", "$coord[0]", "$coord[1]") 
Until $o = $checkbox
You have your $o = $o + 1 outside a loop, so it will only ever = 1 for starters.

Your mouseclick doesn't know how many times to click for 2.

Opt("PixelCoordMode", 0); If your Coords are Window Coords / 2 if client coords / 1 if screen coords
Opt("MouseCoordMode", 0); same as above
; If your trying to click in a window
; Opt("WinTitleMatchMode", 4)
; $WINDOW = "Title Of Window"

$tid = inputbox( "Checkbox tid", "How long should Checkbox run (Hours)?", "24",)
$checkbox = $tid * 6 * 60

$o = 1

Do

$coord = PixelSearch( 157, 170, 567, 537, 0x00ff00, 30)

If Not @error Then

If Not WinActive($WINDOW) Then WinActivate($WINDOW)
Sleep(200)
MouseClick ("left", $coord[0], $coord[1], 1, 1)
EndIf

Sleep(55)
$o = $o + 1

Until $o = $checkbox

Edit: Forgot /Code Tag

Edit2: Noticed there were quotation marks around the variables B)

Edit3: LXP's Code is cleaner (Of Course, I just went off what you were doing already)

Edited by ronsrules

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

Welcome to the forums! Looks like Ron has beat me to it but I'll post anyway... B)

The problem is that you're comparing the return value of PixelGetColor() (a numeric value) to a string. Actually, you are using quotes in some other places that you probably shouldn't:

  • "0x00ff00" => 0x00ff00
  • "$coord[0]" => $coord[0]
One other small problem I can see is that because your code to increment $o lies outside the loop, your loop will run forever. Try this code out for size:

; Declare your variables!
Local $Duration = InputBox('CheckBox', 'How many hours should CheckBox run?', 24)

; Convert to a value useable by TimerDiff()
$Duration = $Duration * 1000 * 60 * 60

; Note the start time
Local $StartTime = TimerInit()

; Loop until the end time is reached
While TimerDiff($StartTime) < $Duration
    Local $Coords = PixelSearch(157, 170, 567, 537, 0x00ff00)
; @Error won't be set if the colour was found
    If Not(@Error) Then MouseClick('Left', $Coords[0], $Coords[1])
WEnd
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...