Sign in to follow this  
Followers 0
Danger111

Do smth every X amount of Time

20 posts in this topic

Hello

For example i have a script like this:

While 1
Mousemove(0,0, 10)
Mousemove(10,10,10)
Wend

What i want to do is, to make the script break this While loop and Mousemove(20,20,10) every X amount of time, (Let's say every 60 seconds).

I mean even if the while loop is not ended so, the script has just moved the mouse to 0,0 coordinates (Mousemove(0,0,10) but (60 seconds) has passed so script won't move mouse to 10,10 coordinates (Mousemove(10,10,10) and will move mouse to 20,20 coordinates and the start the while loop from the begginning.

Thanks!

Share this post


Link to post
Share on other sites



Hi,

Take a look at the Sleep function.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You may need to look at the Sleep command and maybe using addition with coordinates as variables.

i.e. Similar to the following perhaps

$a = 0

$b = 0

$c = 0

While 1

Sleep(1000)

MouseMove($a, $b, $c)

$a = $a + 10

$b = $b + 10

$c = $c + 10

If $c = 500 Then ExitLoop

Wend

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

Can you please tell us the purpose of this script? Do you just want to learn AutoIt or do you need to solve a real problem?

If we know what you want to achive we might suggest an easier and even more reliable way.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Okay, you understood my problem differently guys. I brought that mousemove while loop as an example.

I will expalin what i want to know better

For Example i have a script whith main while loop:

While 1
; a whole bunch of script here with If statements, for loops, and so on
Wend

I want the script to stop the while loop and for example Msgbox(0, 'Title', "Text"), every 60 seconds and then start the while loop again.

Okay, if it's still confusing let me introduce another example (it seems Mousemove have lost you):

Script:

While 1
Msgbox(0, "Box1", "Box2")
Sleep(1000)
Msgbox(0, "Box2", "Box2")
Wend

Here we have a script, which makes first a Msgbox appear wth title and text: Box1 and after that a Msgbox with title and text: Box2

I want every 60 seconds the script to make a Msgbox with title and Text: Box3 (Msgbox(0, "Box3", "Box3"))

And finally why i am asking this question: I have a script that does something continuously with While 1 Loop (I don't want to upload a whole script), and i wan't to make my script to break the This while loop every 60 seconds then do something for example move mouse and start the while loop all over again.

Sorry for my bad english and if i was not able to explain my problem clearly

Thanks!

Edited by Danger111

Share this post


Link to post
Share on other sites

While 1
    Mousemove(0,0, 10)
    Mousemove(10,10,10)
    Sleep(60000)
    MsgBox(0, "", "That was so hard.")
Wend


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

I thought about that option too, but I was too lazy as the OP is to add it.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Is it so hard to understand what i am asking? The script FireFox replied:

While 1
Mousemove(0,0, 10)
Mousemove(10,10,10)
Sleep(60000)
MsgBox(0, "", "That was so hard.")
Wend

This script moves mouse to 0,0 then to 10,10 and waits 60seconds i could do that myself too. What i want to do is, that when i have a While loop, ok let's say that Mousemove loop:

While 1
Mousemove(0,0, 10)
Mousemove(10,10,10)
Wend

I want every 60 seconds script to STOP/BREAK (call whatever you like) this WHILE LOOP then do something else (For example move mouse on random coordinates Say X, Y only once) and START the WHILE LOOP again.

Thanks!

Edited by Danger111

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Okay, I solved the half of my Problem: It seems i had to use AdlibRegister function here is my script:

HotKeySet("E", "_Exit")
AdlibRegister("_Break", 6000)

while 1
MouseMove(0,0,10)
sleep(1000)
MouseMove(1887, 977,10)
WEnd

Func _Break()
Mousemove(889, 471,10)
EndFunc

Func _Exit()
Exit
EndFunc

But the problem is when the Adlib uses _Break function the While loop continues from where he stopped, i want after the Break function while loop to start from the beginning. Is it possible?

Thanks!

Edited by Danger111

Share this post


Link to post
Share on other sites

Put the while loop in a function. Leave the function when you wish, then call the function again.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Hmm i have tried it like this:

HotKeySet("E", "_Exit")
AdlibRegister("_Break", 6000)

_start()

Func _Start()
while 1
MsgBox(0, "Box1", "Box1")
MsgBox(0, "Box2", "Box2")
MsgBox(0, "Box3", "Box3")
WEnd
EndFunc

Func _Break()
MsgBox(0, "Box4", "Box4")
_start()
EndFunc

Func _Exit()
Exit
EndFunc

Resut: After first 6 seconds Box4 appears and then the while loop starts from begginging (From Box1), but after first 6 seconds Box4 never appears it's like AdlibRegister stopped working, any ideas?

Thanks!

Edited by Danger111

Share this post


Link to post
Share on other sites

Is it so hard to understand what i am asking?

I would say yes if I was not the only one to answer wrongly but it's not the case.

I doubt the script purpose is legit (to the forum rules)...


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

That's what I asked for in post #4. But the OP refused to answer my question.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Whats not legit in asking how to break a Loop every X amount of time and then start it again?

Or because i don't want to upload my script you decided that i am writing some hacking program or virus?

Anyway from my #13 post i think my question is clear and if you got a solution please reply me.

Thanks!

Edited by Danger111

Share this post


Link to post
Share on other sites

Whats not legit in asking how to break a Loop every X amount of time and then start it again?

Or because i don't want to upload my script you decided that i am writing some hacking program or virus?

Anyway from my #13 post i think my question is clear and if you got a solution please reply me.

Thanks!

No, you refuse to say what you are automating. I too think you are doing something we do not allow here.

Share this post


Link to post
Share on other sites

I think adlibregister will interrupt your start function, and cause recursion.

You can code your script with different logic, or add a global flag to set in _Break() and reset in _start() and have _start() return to control the recursion.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

@Danger111

If the replies to this topic has frustrated you, try testing this example for an extended length of time when your a little tired.

It should cure you.

; The chance of the AdlibRegister's function returning
; to the loop after any of the If statements to execute
; the following command line is possible, but unlikely.
Global $Flag = 1
HotKeySet("E", "_Exit")
AdlibRegister("_Break", 6000)

_start()

Func _Start()
    While 1
        $Flag = 1
        MouseMove(0, 0, 10)
        If $Flag = 0 Then ContinueLoop
        Sleep(1000)
        If $Flag = 0 Then ContinueLoop
        MouseMove(587, 377, 10)
        If $Flag = 0 Then ContinueLoop
        MsgBox(0, "Box1", "Box1", 1)
        If $Flag = 0 Then ContinueLoop
        MsgBox(0, "Box2", "Box2", 1)
        If $Flag = 0 Then ContinueLoop
        MsgBox(0, "Box3", "Box3", 1)
    WEnd
EndFunc   ;==>_Start

Func _Break()
    MouseMove(20, 350)
    MsgBox(0, "Box4", "Box4")
    $Flag = 0
EndFunc   ;==>_Break

Func _Exit()
    Exit 0
EndFunc   ;==>_Exit
1 person likes this

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

@Malkey

Yep, that works exactly as i wanted. Thank you so much.

Thanks a lot all of you for spending your time helping me and special thanks to Malkey for solving my problem:)

Thanks!

Edited by Danger111

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