Skip to content Skip to sidebar Skip to footer

Ahk Loop Running Again After Break

  • Members
  • 4 posts
  • Last agile: Feb 24 2014 12:25 AM
  • Joined: 23 February 2014

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


  • Back to top

kakashi524

  • Members
  • 103 posts
  • Last active: Apr 18 2015 11:41 PM
  • Joined: 25 Feb 2013

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.


  • Dorsum to top

jane35

  • Members
  • 4 posts
  • Last active: February 24 2014 12:25 AM
  • Joined: 23 Feb 2014

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


  • Back to tiptop

MilesAhead

  • Members
  • 578 posts
  • Last active: Feb 29 2016 05:15 PM
  • Joined: 21 Jan 2009

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.


"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

dmg

  • Members
  • 2395 posts
  • Last active: November 04 2015 06:46 AM
  • Joined: nineteen November 2010

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. B)


"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

jane35

  • Members
  • 4 posts
  • Terminal agile: Feb 24 2014 12:25 AM
  • Joined: 23 Feb 2014

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


  • Back to pinnacle

dmg

  • Members
  • 2395 posts
  • Last active: Nov 04 2015 06:46 AM
  • Joined: nineteen Nov 2010

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. ;)


"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

jane35

  • Members
  • 4 posts
  • Concluding active: Feb 24 2014 12:25 AM
  • Joined: 23 Feb 2014

Ok thanks for your help

Many cheers

Jane


  • Back to height

williamswroure.blogspot.com

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"