Jump to content

AutoIt loop doesnt work for me.


ChawuS
 Share

Recommended Posts

Hi all, I do really appreciated if someone helps me to basic script to loop forever until I press "ESC" key. Here is the code below I dont know whats wrong in the code but it doesnt work. Code itself basic action if specific pixel green, mouse click pixel ELSE mouse click different location. I just need to loop these but somehow its not looping. When I put the "while" on top its only looping if statement rule 1. Any helps appreciated pleaaaasee!

 

Quote

WinActivate("TEST")

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

Local $color = PixelGetColor (165, 550)

Func cancel()
    Exit
EndFunc


if $color = "0x41C80F" Then
      sleep(1000)
      MouseClick("left", 165,550) ;CHECK JOB

Else
      sleep(1000)
      MouseClick("left", 550,630) 

EndIf

While(1)
      Sleep(2000)
WEnd

 

Link to comment
Share on other sites

WinActivate("TEST")

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

Local $color
While 1
    $color = PixelGetColor (165, 550)

    If $color = "0x41C80F" Then
        sleep(1000)
        MouseClick("left", 165,550) ;CHECK JOB
    Else
        Sleep(1000)
        MouseClick("left", 550,630) 
    EndIf
    Sleep(2000)
WEnd 

Func cancel()
    Exit
EndFunc

It helps if you put your code inside your loop.;)

And welcome to the AutoIt forums.:)

Edited by RTFC
Link to comment
Share on other sites

18 minutes ago, RTFC said:
WinActivate("TEST")

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

Local $color
While 1
    $color = PixelGetColor (165, 550)

    If $color = "0x41C80F" Then
        sleep(1000)
        MouseClick("left", 165,550) ;CHECK JOB
    Else
        Sleep(1000)
        MouseClick("left", 550,630) 
    EndIf
    Sleep(2000)
WEnd 

Func cancel()
    Exit
EndFunc

It helps if you put your code inside your loop.;)

Thanks for the speedy response but however it doesnt work. Its looping but if statement doesnt work. I mean whatever the pixel is "0x41C80F"  or not its working like order first mouseclick 165,550 then its click 550,630. Its looping all scenario. Any ideas why its doing this?

Link to comment
Share on other sites

  • Developers
42 minutes ago, ChawuS said:

Any ideas why its doing this?

You seriously think we would be able to answer that without being able to test it ourselves?

So what exactly are you trying to do and what do you expect it to do?

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

12 minutes ago, Jos said:

You seriously think we would be able o answer that without being able to test it ourselves?

So what exactly are you trying to do and what do you expect it to do?

Jos

basically simple thing; 

- script loop forever until I press "ESC"

- if PIXELlocation 165,550 is green click 165,550 continuously every 1sec ,,ELSE,, PIXELlocation 165,550 color is not green click 550,630 continuously every 1sec.

its working on webpage/internet explorer there is button on pixel 165,550 is green-color if the system goes down, it turns to red... clicking to red button its rebooting the system and button turn green again.

 

so its basic script what I want;

if the button is green keep clicking green-button, if the button turns to red click red-area until button color get back to green, once its green again keep clicking green-button like as first statement. 

Link to comment
Share on other sites

  • Developers

Ok..  so what exactly in not working at the moment as that explanation 2 posts up isn't clear to me?
Just add some consolewrite() statements in the script so you can trace what the script is doing exactly when running from SciTE.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

3 hours ago, Jos said:

Ok..  so what exactly in not working at the moment as that explanation 2 posts up isn't clear to me?
Just add some consolewrite() statements in the script so you can trace what the script is doing exactly when running from SciTE.

Jos

Ok basically,

if statement is not working.

its perfectly looping but its click both statements in order. first its clicking 165,550 and second click 550,630.

What I expect?

if color green click 165,550 continuously if color change to red (or else) click 550,630 continuously until color green, in forever loop.

 

I hope its clear now. Please let me know if need any info. Also I do really really appreciated for your help. Thank you ever so much indeed. 

Link to comment
Share on other sites

  • Developers

Did you do what I suggested and add those debug statements so you can see why it is doing that?
You are the only person that can do this!

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

3 minutes ago, Jos said:

Did you do what I suggested and add those debug statements so you can see why it is doing that?
You are the only person that can do this!

Jos

Im adding consolewrite() now. I ll copy and paste the results.

Link to comment
Share on other sites

24 minutes ago, Jos said:

Did you do what I suggested and add those debug statements so you can see why it is doing that?
You are the only person that can do this!

Jos

 
 
 
 
Quote

WinActivate("TEST")

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

Local $color
While 1
    $color = PixelGetColor (165, 550)
consolewrite($color & @CRLF)
    If $color = "4310555" Then
        sleep(1000)
        MouseClick("left", 165,550)
        sleep(1000)
        MouseClick("left", 165,550)
        sleep(1000)
        MouseClick("left", 165,550)
    Else
        Sleep(1000)
        MouseClick("left", 695,50)
        Sleep(1000)
        MouseClick("left", 695,50)
        Sleep(2000)
    EndIf
    Sleep(2000)
WEnd

Func cancel()
    Exit
 EndFunc

 
 
 
 
Quote

>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\BSPC\Documents\TEST.au3"    
2009462
4310555
2009462
4310555
2009462
4310555
2009462
>Exit code: 0    Time: 37.27

Here is the results Jos, the pixel 165, 550 always color coded 4310555 but somehow its clicking 3 times 165,550 then jump to else section run the else statements which is clicking 2 times 695,50....

 

What I expect clicking if statements 4310555 color until button changed color,, if it changed goto else do the else clicks..

Link to comment
Share on other sites

  • Developers

I was thinking more of these trace lines and also guess the If was never true since you have the color as string!
Have a look at this version and see what it does for you.

WinActivate("TEST")

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

Local $color
While 1
    $color = PixelGetColor (165, 550)
    ConsoleWrite('+ $color = ' & $color & " - " & Hex($color, 6) & @CRLF) ;### Debug Console
    If $color = 0x41C80F Then
        sleep(1000)
        ConsoleWrite('> Left click on (165,550)' & @CRLF) ;### Debug Console
        MouseClick("left", 165,550) ;CHECK JOB
    Else
        Sleep(1000)
        ConsoleWrite('! Left click on (550,630) ' & @CRLF) ;### Debug Console
        MouseClick("left", 550,630)
    EndIf
    Sleep(2000)
WEnd

Func cancel()
    Exit
EndFunc

So you really need to try and understand what you are doing and how to properly go about testing!

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

17 minutes ago, Jos said:

I was thinking more of these trace lines and also guess the If was never true since you have the color as string!
Have a look at this version and see what it does for you.

WinActivate("TEST")

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

Local $color
While 1
    $color = PixelGetColor (165, 550)
    ConsoleWrite('+ $color = ' & $color & " - " & Hex($color, 6) & @CRLF) ;### Debug Console
    If $color = 0x41C80F Then
        sleep(1000)
        ConsoleWrite('> Left click on (165,550)' & @CRLF) ;### Debug Console
        MouseClick("left", 165,550) ;CHECK JOB
    Else
        Sleep(1000)
        ConsoleWrite('! Left click on (550,630) ' & @CRLF) ;### Debug Console
        MouseClick("left", 550,630)
    EndIf
    Sleep(2000)
WEnd

Func cancel()
    Exit
EndFunc

So you really need to try and understand what you are doing and how to properly go about testing!

Jos

Jos! You re STAR mannnn!!! Its working now the reason is there is 2 colors because of mouse highlight. I put "or" in if statement first line now its working like a Charm!!!!! Thank you sooooooooooo much ever !!!

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...