 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Ethrock Guest
|
Posted: Wed Apr 15, 2009 11:02 am Post subject: Looping Issue |
|
|
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
|
|
|
| Back to top |
|
 |
Slanter
Joined: 28 May 2008 Posts: 739 Location: Minnesota, USA
|
Posted: Wed Apr 15, 2009 7:30 pm Post subject: |
|
|
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 Fri Apr 17, 2009 3:07 am; edited 1 time in total |
|
| Back to top |
|
 |
Ethrock Guest
|
Posted: Thu Apr 16, 2009 7:54 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Guest++ Guest
|
Posted: Thu Apr 16, 2009 9:52 am Post subject: |
|
|
You can use a timer.
| Code: |
If condition := true
settimer, your_timer, on ; or period
else
settimer, your_timer, off
|
|
|
| Back to top |
|
 |
Ethrock Guest
|
Posted: Thu Apr 16, 2009 9:50 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Slanter
Joined: 28 May 2008 Posts: 739 Location: Minnesota, USA
|
Posted: Fri Apr 17, 2009 3:07 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Ethrock Guest
|
Posted: Fri Apr 17, 2009 11:16 am Post subject: |
|
|
| 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... |
|
| Back to top |
|
 |
Ethrock Guest
|
Posted: Sat Apr 18, 2009 10:28 am Post subject: |
|
|
| 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! |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|