user1830525
user1830525

Reputation:

Alternative to using the Sleep function?

How do you run a loop uninterrupted by a Sleep command that is activated by another hotkey command in the same script? I know an easy work around is to have 2 ahk files but I would like to consolidate into just one script.

My sample code for example. The wav files are in the same folder location so that work for me. The script will ignore the SoundPlay commands otherwise. As the code is now, the loop works fine but then gets disabled everytime I run the RandomLabel hotkey (pressing s on the keyboard) but gets enabled again after the Sleep command expires.

Esc::Reload 
+1::Test()  
Test()  
{  
SoundPlay,Activated.wav  
Hotkey,~s,RandomLabel,Toggle  
loop  
{  
    PixelGetColor,color,707,721,Slow  
    if(color=0xFFFFFF)  
    {  
        SoundPlay,Pong.wav  
        loop  
        {  
            PixelGetColor,color,707,721,Slow  
            if(color=!0xFFFFFF)  
            {  
                SoundPlay,Ping.wav  
                break  
            }  
        }  
    }  
}  
}  
RandomLabel:  
Sleep,2000  
SoundBeep,750,300  
return  

Edit: The objective of the code is to run an uninterrupted loop while having a hotkey activate a countdown timer before playing a soundfile. This is all done in autohotkeys1 specifically if possible.

Upvotes: 2

Views: 2181

Answers (1)

NbdNnm
NbdNnm

Reputation: 528

Try SetTImer.

RandomLabel:  
    settimer, LabelSoundBeep, -2000
return  
LabelSoundBeep:
    SoundBeep,750,300  
return

Upvotes: 1

Related Questions