Sign in to follow this  
Followers 0
m0rfin

Unlimited looping?

4 posts in this topic

Hi, im trying to make a simple timer script that presses a key in a certain time. But i cant get it to loop.. so i was wondering if someone could help me?

Func toggla()
    Send ("{F9}")
    Sleep(120000)
    Send ("{F8}")
    Sleep(25000)
EndFunc
HotKeySet("f","toggla");


While 1
WEnd

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Your loop is not calling anything.

try this

HotKeySet("f","toggla"); Placing the hotkey in here is not necessary, but will allow you to do the function manually if you want to.
 HotKeySet("{ESC}", "Terminate");a way to break out of the script
 
 While 1
 Toggla()
 sleep(100); or however long you want to wait in microseconds.  
 WEnd
Func toggla()
     Send ("{F9}")
     Sleep(120000)
     Send ("{F8}")
     Sleep(25000)
 EndFunc
Func Terminate()
    Exit
EndFunc
Edited by Kerros

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi, im trying to make a simple timer script that presses a key in a certain time. But i cant get it to loop.. so i was wondering if someone could help me?

Func toggla()
    Send ("{F9}")
    Sleep(120000)
    Send ("{F8}")
    Sleep(25000)
EndFunc
HotKeySet("f","toggla");


While 1
WEnd
The way you have written your scipt means that when you press the key f the function toggla will be called. It will execute the statements then finish.

You could change the function so that it keeps looping like this

Func toggla()
  while 1
    Send ("{F9}")
    Sleep(120000)
    Send ("{F8}")
    Sleep(25000)
  wend
endfunc

You then have a problem because there is no way to stop it looping. So have some way of stopping Toggla. Maybe like this

Global $keepGoing
HotKeySet("f", "toggla");
HotKeySet("g", "EndToggla")


While 1
   sleep(100);add a sleep here or it will use a lot of CPU time when it's not executing toggla
WEnd

Func toggla()
    $keepGoing = True
    While $keepGoing = True
        Send("{F9}")
        Sleep(120000)
        Send("{F8}")
        Sleep(25000)
    WEnd
EndFunc ;==>toggla

Func EndToggla()
    $keepGoing = False
EndFunc ;==>EndToggla
Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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