AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help with loops, mildly confused.

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
The.Yield



Joined: 08 Jul 2009
Posts: 10

PostPosted: Tue Sep 15, 2009 10:04 pm    Post subject: Help with loops, mildly confused. Reply with quote

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 Laughing

Hopefully someone can help me out on this one. Thanks.

Long live AHK.
Back to top
View user's profile Send private message
Carcophan



Joined: 24 Dec 2008
Posts: 1308
Location: :noitacoL

PostPosted: Tue Sep 15, 2009 10:13 pm    Post subject: Reply with quote

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
View user's profile Send private message
The.Yield



Joined: 08 Jul 2009
Posts: 10

PostPosted: Wed Sep 16, 2009 12:09 am    Post subject: Reply with quote

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 Laughing
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
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group