Jump to content

Need some help with loop please.


Recommended Posts

HotKeySet("{ESC}", "On_Exit") ;quick way out if something goes wrong

#include <AutoItConstants.au3>

Global $searchforspecficpixel

While 1

$searchforspecficpixel1 = PixelSearch (-1403, 567, -1373, 586, 0x5181BF)

If Not @error Then ;plays wav file if pixel is found
     SoundPlay (@DesktopDir & "\MP3s & WAV\Computer_Magic-10sec.wav", 1)
EndIf
Sleep (5000)

If Not @error Then ;refreshes page
    MouseClick ("left", -1455, 714)
EndIf
Sleep (10000)

WEnd

Func On_Exit()
    Exit
EndFunc

If pixel is found I would like for the wav file to play over and over but I would like for the MouseClick to stop. I have searched for nested loops (not sure if this is what I should be looking for) but cannot fine the answer. Could someone point me to a tutorial as to how I can make this happen? Also, if I don't put a 1 behind While the script doesn't work. What is the purpose of the 1?

Thank you in advance for any help,
yeto

Link to comment
Share on other sites

@yeto

Pixel* and Mouse* functions are not the best ones to automate something.

If you could tell us what you are trying to automate, maybe there's a better way to do it.

By the way

53 minutes ago, yeto said:

What is the purpose of the 1?

1 is intended as the boolean value of True, and the While loop is executed until the condition is true; so, if you put a 1 or a True next to a While instruction, it will loop "infinitely" :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

27 minutes ago, FrancescoDiMuro said:

@yeto

Pixel* and Mouse* functions are not the best ones to automate something.

If you could tell us what you are trying to automate, maybe there's a better way to do it.

By the way

1 is intended as the boolean value of True, and the While loop is executed until the condition is true; so, if you put a 1 or a True next to a While instruction, it will loop "infinitely" :)

I am monitoring a section of a web-page and I need an alarm when the section/pixel changes (wav file is the alert/alarm) and to check for changes I need to periodically refresh the page (mouse click click on refresh).

Link to comment
Share on other sites

16 minutes ago, FrancescoDiMuro said:

@yeto

Do you have access to the source code of the web-page?

In that case, it could be easily achievable with _IE* functions :)

Yes, I have access to the source code. Can you point me to a tutorial or an example as to how this is used? I am studying this page now.

https://www.autoitscript.com/autoit3/docs/libfunctions/IE Management.htm

Edited by yeto
Link to comment
Share on other sites

1 hour ago, FrancescoDiMuro said:

@yeto

You choose a good point where to start.

"Spy" the various elements in the webpage and see if you can use _IEGetObjBy* functions to obtain the information needed; you can then refresh the webpage with _IEAction($objIE, "refresh") :)

Thank you. Thank you. I will give it a go.

Link to comment
Share on other sites

 

2 hours ago, FrancescoDiMuro said:

@yeto

You choose a good point where to start.

"Spy" the various elements in the webpage and see if you can use _IEGetObjBy* functions to obtain the information needed; you can then refresh the webpage with _IEAction($objIE, "refresh") :)

After further review I think nesting the loops will be easier. I just have to figure out a way to separate the mouse click when not needed and to loop the wav file when needed.

Thank you,
yeto

 

Link to comment
Share on other sites

1 hour ago, Network_Guy said:

so u need to refresh web page every 10 sec or  only refreshing it if pixelsearch found the the desired pixel ?

Thank you for replying. I need to refresh every 10 seconds until pixel is found. If pixel is found I would like for refreshing to stop and wav file to play until I ESC out. Any help would be greatly appreciated.

Thank you,
yeto

Edited by yeto
Link to comment
Share on other sites

7 hours ago, yeto said:

Thank you for replying. I need to refresh every 10 seconds until pixel is found. If pixel is found I would like for refreshing to stop and wav file to play until I ESC out. Any help would be greatly appreciated.

Thank you,
yeto

Try this code :-

HotKeySet("{ESC}", "On_Exit") ;quick way out if something goes wrong

#include <AutoItConstants.au3>

Global $searchforspecficpixel
Global $RefreshTimer = TimerInit()

While 1

    $searchforspecficpixel1 = PixelSearch(-1403, 567, -1373, 586, 0x5181BF)

    If Not @error Then ;plays wav file if pixel is found
        SoundPlay(@DesktopDir & "\MP3s & WAV\Computer_Magic-10sec.wav", 1)
        $RefreshTimer = TimerInit()
        Sleep(5000)

    Else
        If TimerDiff($RefreshTimer) > 10000 Then ;refreshes page
            MouseClick("left", -1455, 714)
            $RefreshTimer = TimerInit()
        EndIf
    EndIf
WEnd

Func On_Exit()
    Exit
EndFunc   ;==>On_Exit

this code will check for pixel :-
if pixel is not found it will keep refresh page every 10 sec.
if pixel is found it will keep playing sound without refreshing page until you use {ESC} or pixel not found

Edited by Network_Guy
Link to comment
Share on other sites

9 hours ago, Network_Guy said:

Try this code :-

HotKeySet("{ESC}", "On_Exit") ;quick way out if something goes wrong

#include <AutoItConstants.au3>

Global $searchforspecficpixel
Global $RefreshTimer = TimerInit()

While 1

    $searchforspecficpixel1 = PixelSearch(-1403, 567, -1373, 586, 0x5181BF)

    If Not @error Then ;plays wav file if pixel is found
        SoundPlay(@DesktopDir & "\MP3s & WAV\Computer_Magic-10sec.wav", 1)
        $RefreshTimer = TimerInit()
        Sleep(5000)

    Else
        If TimerDiff($RefreshTimer) > 10000 Then ;refreshes page
            MouseClick("left", -1455, 714)
            $RefreshTimer = TimerInit()
        EndIf
    EndIf
WEnd

Func On_Exit()
    Exit
EndFunc   ;==>On_Exit

this code will check for pixel :-
if pixel is not found it will keep refresh page every 10 sec.
if pixel is found it will keep playing sound without refreshing page until you use {ESC} or pixel not found

Yes, that works perfectly. Thank you.

I have a few questions if you have time to teach. I just started coding but I wanted to ask how did you know to use TimerInit? I could have searched for the rest of my life and never come up with that solution. I have studied the help file and I can't even understand what purpose TimerInit is serving in this application but it works.

Also, at times I will need to check more than 1 area of the browser window (maybe up to 4 or 5 blocks) for pixel change. Would this code be hard to modify to accomplish that?

Again, thank you for taking time to help,
yeto

Link to comment
Share on other sites

48 minutes ago, Earthshine said:

he read the helpfile, that's how he knows. i suggest you read though it and do all the examples, and learn what the examples are teaching. spoon feeding you is really annoying.

Read the above post. Did you not see where I said I studied the help file. Now lay your little head down and go back to sleep if you don't have anything to offer.

Edited by yeto
Link to comment
Share on other sites

@yeto

Without getting in count the bad words you said to an older member of AutoIt, you have to think and know that everyone has started from zero.

The road everyone builds up during the spare time, or whenever you can take a look at Help file, at Forums, and so on, depends from what everyone wants, so, if you would really whant to know more about the functions used in the script above, why do they work in that way, and how can you use them at your advantage, then you need to take a look at the Help file, try some scripts, study the behaviour of the functions, and everything else behind the scenes.

The limit is the willingness everyone puts to see what's going on over the horizon :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

39 minutes ago, FrancescoDiMuro said:

@yeto

Without getting in count the bad words you said to an older member of AutoIt, you have to think and know that everyone has started from zero.

The road everyone builds up during the spare time, or whenever you can take a look at Help file, at Forums, and so on, depends from what everyone wants, so, if you would really whant to know more about the functions used in the script above, why do they work in that way, and how can you use them at your advantage, then you need to take a look at the Help file, try some scripts, study the behaviour of the functions, and everything else behind the scenes.

The limit is the willingness everyone puts to see what's going on over the horizon :)

he said: "spoon feeding you is really annoying"

Why would anyone use those words in a help forum unless they are just trying to cause trouble?

I said: "I have studied the help file and I can't even understand what purpose TimerInit is serving in this application but it works."

I plainly said I had studied the help file and I still didn't understand how the code worked. I kindly asked, that if the poster had time, that maybe he could explain it to me.

Your replies have always been helpful. I certainly know this is going to be a long, hard road that will take a lot of effort but if you come to my house and say you have been trying to play a G chord on guitar and you just can't get it I am not going to tell you to go search the internet. I will take the time to actually show you how to play the chord.     

Edited by yeto
Link to comment
Share on other sites

i just took your question you posted here and googled it, and guess what, I found a whole list of threads just like this already solved. it shows  you are not putting in any effort to search the forums, the help file or google. instead you hammer this site with every little thing, and seem to me to want to have ready made code, then to have someone "teach" it to you.

search string:

loop refresh every 10 seconds autoit

 

Look, just use this thread as a learning point, to learn to use the search function on this forum first, google second, helpfile third (Three before me--God, I never thought I would have to say that)

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

2 hours ago, Earthshine said:

i just took your question you posted here and googled it, and guess what, I found a whole list of threads just like this already solved. it shows  you are not putting in any effort to search the forums, the help file or google. instead you hammer this site with every little thing, and seem to me to want to have ready made code, then to have someone "teach" it to you.

search string:

loop refresh every 10 seconds autoit

 

Look, just use this thread as a learning point, to learn to use the search function on this forum first, google second, helpfile third (Three before me--God, I never thought I would have to say that)

I don't want to get in a back and forth with you but the thread you provided did not explain the purpose of the TimerInit function in the above script so why don't you enlighten me an explain it yourself?

Thanks for trying to help,
yeto

Link to comment
Share on other sites

@yeto

The thread @Earthshine posted, is full of samples in which TimerInit() is used.

TimerInit() and TimerDiff() are two functions (you'd never say) used to do something every some time, or check how many seconds are passed to complete thr script, and so on.

TimerInit(), where Init stands for Initialize (?), returns an handle that can be used later with TimerDiff().

TimerDiff(), where Diff stands for Difference (?), returns how many milliseconds are passed from the TimerInit().

Let's take an example: if you'd like to know how much time the script executes all the instruction, how would you do that?

Just put a TimerInit() at the beginning of your script (a sort of "Start timer, always from 0"), and a the end of the script, you put a TimerDiff()/1000 with Round() function to see how many seconds your script took to be executed.

Look in the Help file too :)

 

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

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