 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
The.Yield
Joined: 08 Jul 2009 Posts: 10
|
Posted: Tue Sep 15, 2009 10:04 pm Post subject: Help with loops, mildly confused. |
|
|
Thanks in advance to anyone who can help me out with this one; it goes beyond my skill level with AHK.
I suppose I'll start with exactly what it is I'm trying to do:
I want to press !w:: and have the script continuously hold down the W key --AND-- press the T key once every 7 seconds, forever, until I press !w:: again. And preferably with an active window requirement.
In concept, this seemed like something I could pull-off. So I tried to learn and incorporate loops and breaks, etc. Needless to say, what has resulted so far has been function-less garbage
Hopefully someone can help me out on this one. Thanks.
Long live AHK. |
|
| Back to top |
|
 |
Carcophan
Joined: 24 Dec 2008 Posts: 1308 Location: :noitacoL
|
Posted: Tue Sep 15, 2009 10:13 pm Post subject: |
|
|
There are hundreds of examples of this found using the term 'toggle', in the search and 'title only' option.
This is the example from the AHK help file, easily adaptable to your needs
| Code: |
#MaxThreadsPerHotkey 3
#z:: ; Win+Z hotkey (change this hotkey to suit your preferences).
#MaxThreadsPerHotkey 1
if KeepWinZRunning ; This means an underlying thread is already running the loop below.
{
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
{
; The next four lines are the action you want to repeat (update them to suit your preferences):
ToolTip, Press Win-Z again to stop this from flashing.
Sleep 1000
ToolTip
Sleep 1000
; 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 |
quick, untested edit:
| Code: |
!w:: ; alt W
if KeepWinZRunning
{
KeepWinZRunning := false
return
}
KeepWinZRunning := true
Loop
{
;send your sleep and 'T' commands here
Send, T
Sleep 7000 ; 1 second = 1000 Milisecond
}
KeepWinZRunning := false return |
|
|
| Back to top |
|
 |
The.Yield
Joined: 08 Jul 2009 Posts: 10
|
Posted: Wed Sep 16, 2009 12:09 am Post subject: |
|
|
That works great! It taps T every 7 seconds perfectly, forever.
Now it just needs to hold down the W key forever, or alternatively, press the R key once when the script activates, and once when it turns off.
And to that end, the example you've provided never turns off
I'd do it myself, but I'm not entirely certain how to integrate those two requirements into what you've provided.
Thanks in advance for 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
|