Ahk Loop Running Again After Break
Sorry if this is a very basic question, simply I have just joined autohotkey and been trying to figure this out for about 3 hours without any luck.
What I accept is a very basic script (plant on the help section) that when I press F1 key it toggles a loop. What I want to do is keep the F1 cardinal to toggle the loop, but take the option that if I don't press F1 key within 10 minutes then the loop will finish.
And so how do I enable the loop to break automatically after 10 minutes too having the selection to toggle with F1
Many thanks
Jane
Here if my simple code:
#MaxThreadsPerHotkey 3
F1::
#MaxThreadsPerHotkey 1
if KeepWinZRunning
{
KeepWinZRunning := false
render
}
; Otherwise:
KeepWinZRunning := true
Loop
{
Send {F2}
Sleep 1000
Send {Enter}
if not KeepWinZRunning
pause ; Break out of this loop.
}
KeepWinZRunning := false
#ane - Posted 23 February 2014 - 09:20 PM
-
Back to top
Hi, I wrote a counter code some time back to examination the A_TickCount command.
F7:: if start = 0 { StartTime := A_TickCount starting time := i } else if start = 1 { ElapsedTime := A_TickCount - StartTime start := 0 } Return F8:: MsgBox, %ElapsedTime% milliseconds accept elapsed. Return
What you want to do is:
Every fourth dimension you press the F1 Fundamental, y'all run
StartTime := A_Tickcount
And I see that the Loop happens once every 1 second (thou milliseconds). Within the loop add
ElapsedTime := A_Tickcount - StartTIme
to run across how long is has been since the terminal time the F1 cardinal was pressed, and so add an if argument to test if
ElapsedTime > 600000 ;(600000 milliseconds = 10 mins)
if true, then suspension the loop.
Note: The value of A_TickCount increases by i every one millisecond.
#2 - Posted 23 February 2014 - 10:33 PM
-
Dorsum to top
Many thanks for your post, however I am having problems getting this to work. Is there whatsoever run a risk you lot could show me the instance with my uncomplicated code?
Many thanks Jane
#iii - Posted 23 February 2014 - 10:l PM
-
Back to tiptop
For the timed breakout I retrieve I would utilise SetTimer. 10 minutes should be 600,000 ms.
On hitting F2 just impale the timer and set keeprunning to fake. Come across SetTimer in help. It's pretty easy to use.
#four - Posted 23 Feb 2014 - 11:07 PM
"Some people, when confronted with a problem, recollect I know, I'll use regular expressions. Now they have two problems."
- Jamie Zawinski
-
Dorsum to top
For this particular purpose I think a timer would exist sufficient:
#maxthreadsperhotkey, 3 f1:: { settimer, fourth dimension, -600000 toggle := !toggle while, (toggle) { transport {f2} slumber 1000 send {enter} } } return time: { toggle := 0 } return
This code should practise what that example does but information technology is shorter and, I think, simpler to understand.
Edit:
Ahh, MilesAhead. You were in fact 'miles alee' of me this time.
#5 - Posted 23 February 2014 - 11:10 PM
"My dear Mr Gyrth, I am never more serious than when I am joking."
~ Albert Campion
-----------------------------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact
-
Back to top
Many cheers DMG that is perfect and information technology works great. Yous take just saved me many hours.
Just one other thing I was wondering if the unit of fourth dimension could exist changed to seconds instead of MS? Or does AHK only empathise MS unit?
Thanks Jane
#vi - Posted 23 Feb 2014 - 11:31 PM
-
Back to pinnacle
The SetTimer command merely accept ms. Yous will find some commands that do piece of work in seconds, such equally the timeout for the MsgBox command. Basically, if information technology is something intended for humans to interact with and so seconds are used, and if it is something used with code execution, like a timer, then ms are used.
You can convert seconds/ms past multiplying or dividing by one thousand. Every PC has the Calculator app, and so it but takes a second to figure it out.
#vii - Posted 23 February 2014 - 11:44 PM
"My dearest Mr Gyrth, I am never more serious than when I am joking."
~ Albert Campion
-----------------------------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact
-
Back to top
Ok thanks for your help
Many cheers
Jane
#8 - Posted 24 Feb 2014 - 12:19 AM
-
Back to height
Source: https://www.autohotkey.com/board/topic/102299-how-to-break-loop-after-x-amount-of-time-as-well-as-toggle/
Post a Comment for "Ahk Loop Running Again After Break"