Sign in to follow this  
Followers 0
ph34r

Help with Looping + hotkeys!

2 posts in this topic

heres my code

#Region --- ScriptWriter generated code Start ---
Opt("WinWaitDelay", 100)
Opt("WinTitleMatchMode", 4)
Opt("WinDetectHiddenText", 1)
Opt("MouseCoordMode", 0)

HotKeySet("{f1}","LoopFlagToggle")

$loopflag = 0
Do
    sleep(123)
Until $loopflag <> 0

$loopflag = 1
While $loopflag = 1
               Send("{enter}")
        Send("4")
        MouseMove(1003,767)
        MouseDown ("left")
        Sleep(2500)
        MouseMove(991,767)
        Sleep(2500)
        MouseMove(1023,767)
        Sleep(2500)
        MouseUp ("left")
        Sleep(100)
WEnd

Func LoopFlagToggle()
    $loopflag = 1
EndFunc
#EndRegion --- ScriptWriter generated code Start ---

I wanna make it do

Send("{enter}")
        Send("4")
        MouseMove(1003,767)
        MouseDown ("left")
        Sleep(2500)
        MouseMove(991,767)
        Sleep(2500)
        MouseMove(1023,767)
        Sleep(2500)
        MouseUp ("left")
        Sleep(100)

Until i hit F1 again,

So like I open program, then i hit f1 it does the Send n mouse down stuff, then when i hit it again, it stops it.

Whats wrong with my code?

Thank you in advance!

Share this post


Link to post
Share on other sites



The function LoopFlagToggle() is only setting the flag, never clearing it. Try this:

Func LoopFlagToggle()
     If $loopflag Then
          $loopflag = 0
     Else
          $loopflag = 1
     EndIf
EndFunc

Next, you only need one main loop with a single If/EndIf in it to control the function by the flag:

While 1
     If $loopflag Then
         ; Do all the stuff you do...
     EndIf
WEnd

Since you have some long Sleep()s in there, you might want to interrupt it in mid cycle with something like this:

While 1
     If $loopflag Then
         ; Do stuff you do...
          Sleep(2500)
          If Not $loopflag Then ContinueLoop
         ; Do stuff you do...
          Sleep(2500)
          If Not $loopflag Then ContinueLoop
         ; Do stuff you do...
     EndIf
WEnd

muttley


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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