AutoHotkey Community

It is currently May 26th, 2012, 5:30 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Looping Issue
PostPosted: April 15th, 2009, 12:02 pm 
Hey guys I apologize for posting as a guest and being too lazy to register. I also apologize if this question's been asked a million times or if this seems pretty basic.

I need a macro to perform various functions in three different programs, and loop infinitely until interrupted by a hotkey set. I can't get it to do this. Either of these occurs:

1. Loops infinitely and ignores hotkey presses.

2. Goes once, then stops.

Currently #1 is my issue, here's my code:

Code:
#MaxThreadsPerHotkey 3
#z::  ; Win+Z hotkey (change this hotkey to suit your preferences).
#MaxThreadsPerHotkey 1
if KeepWinZRunning 
{
    KeepWinZRunning := false  ; Signal that thread's loop to stop.
    return  ; End this thread so that the one underneath will resume and see the change made by the line above.
}
; Otherwise:
KeepWinZRunning := true
Loop
{
    WinWait, REC,
IfWinNotActive, REC, , WinActivate, REC,
WinWaitActive, REC,
MouseClick, left,  102,  117
Sleep, 5000
WinWait, Calculator,
IfWinNotActive, Calculator, , WinActivate, Calculator,
WinWaitActive, Calculator,
MouseClick, left,  136,  24
Sleep, 1000
Send, {+}0.48{ENTER}
WinWait, REC1 - Notepad,
IfWinNotActive, REC1 - Notepad, , WinActivate, REC1 - Notepad,
WinWaitActive, REC1 - Notepad,
MouseClick, left,  126,  21
Sleep, 1500
Send, {SPACE}48{CTRLDOWN}s{CTRLUP}
WinWait, REC,
IfWinNotActive, REC, , WinActivate, REC,
WinWaitActive, REC,
MouseClick, left,  22,  125
Sleep, 100
    ; But leave the rest below unchanged.
    if not KeepWinZRunning  ; The user signaled the loop to stop by pressing Win-Z again.
        break  ; Break out of this loop.
}
KeepWinZRunning := false  ; Reset in preparation for the next press of this hotkey.
return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 15th, 2009, 8:30 pm 
Offline

Joined: May 28th, 2008, 2:11 am
Posts: 739
Location: Minnesota, USA
I think it may be much simpler to change the basic way it works.
Code:
#MaxThreadsPerHotkey 2
#z::
   LoopZ := !LoopZ
   If (LoopZ) {
      While (LoopZ) {
         ; Code to be looped here
      }
      ; Code to be executed after loop here
   }
Return


ex.
Code:
#MaxThreadsPerHotkey 2
#z::
   LoopZ := !LoopZ
   If (LoopZ) {
      While (LoopZ) {
         A += 1
      }
      MsgBox % A
   }
Return


Note that, should you need to, you can end the loop from anywhere in the script just by setting LoopZ to 0 or blank.

_________________
Unless otherwise stated, all code is untested

(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination.


Last edited by Slanter on April 17th, 2009, 4:07 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 16th, 2009, 8:54 am 
This doesn't seem to allow me to end the loop though, every time I utilize the hotkey, it just restarts the loop. I'm a little confused and apologize for that.

Thanks for this and any further assistance.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 16th, 2009, 10:52 am 
You can use a timer.
Code:
If condition := true
  settimer, your_timer, on ; or period
else
  settimer, your_timer, off



Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 16th, 2009, 10:50 pm 
I'm still not sure how that would achieve my intended goal? I don't want a timer, the macro needs to be able to be left unattended, often for days, then able to be ended immediately with a hotkey press.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 17th, 2009, 4:07 am 
Offline

Joined: May 28th, 2008, 2:11 am
Posts: 739
Location: Minnesota, USA
The code I posted does end with the second press of the hotkey... did you try my example?

_________________
Unless otherwise stated, all code is untested

(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 17th, 2009, 12:16 pm 
Yeah... but when I apply it to the code I'm using (with modifications to remove all the unnecessary untilZ stuff) it simply ignores the hotkey press the second time...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 18th, 2009, 11:28 am 
Ah! My apologies. It d oes work, I left the original Loop { code in and that's why it ignored the hotkey presses. Thanks for all your help!


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: batto, BrandonHotkey, Google [Bot], mrhobbeys, MSN [Bot], Mtes, stanman, Tegno and 65 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group