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 

Need help with simple looping

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



Joined: 22 Oct 2009
Posts: 4

PostPosted: Thu Oct 22, 2009 11:21 pm    Post subject: Need help with simple looping Reply with quote

Hey am really new, gotta start somewhere right Very Happy

i want to press 1,2,3,4 consectivly in a loop
then after 90000 miliseconds
i would like it to pause resuming after 73500 miliseconds


Here is my current script *see below*
which constantly mashes 1234 over and over
Any advice would be great
Thankyou
Quote:
Loop 999999999999
{
Send {1 down}
Sleep 500
Send {1 up}
Sleep 500
Send {2 down}
Sleep 500
Send {2 up}
Sleep 500
Send {3 down}
Sleep 500
Send {3 up}
Sleep 500
Send {4 down}
Sleep 500
Send {4 up}
}

_________________
;
;;
;';.
; ;;
; ;;
; ;;
; ;;
; ;'
; '
,;;;,;
;;;;;;
`;;;;'
Back to top
View user's profile Send private message
Damnyou



Joined: 22 Oct 2009
Posts: 4

PostPosted: Fri Oct 23, 2009 12:30 am    Post subject: Reply with quote

BUMP Crying or Very sad
_________________
;
;;
;';.
; ;;
; ;;
; ;;
; ;;
; ;'
; '
,;;;,;
;;;;;;
`;;;;'
Back to top
View user's profile Send private message
wooly_sammoth



Joined: 12 May 2009
Posts: 634
Location: Gloucester UK

PostPosted: Fri Oct 23, 2009 12:37 am    Post subject: Reply with quote

Take a look at SetTimer.
This command allows you to set a timer (surprisingly) so that your code can be executed at a specified time period
Back to top
View user's profile Send private message Visit poster's website
tekkie2412



Joined: 22 May 2007
Posts: 73

PostPosted: Fri Oct 23, 2009 12:39 am    Post subject: Reply with quote

Try not to double post

Code:

Loop, 900 ;(900 x 100ms = 90000ms)
{
Send, 1234
Sleep, 100
}
Sleep, 73500


Edit:
This is probably a better way to do it, I forgot that you wanted it to resume

Code:

Counter =
While Counter < 901
{
Send, 1234
Sleep, 100
Counter ++

If Counter > 901
{
Sleep, 73500
Counter = 0
}
}


Last edited by tekkie2412 on Fri Oct 23, 2009 1:09 am; edited 2 times in total
Back to top
View user's profile Send private message
Damnyou



Joined: 22 Oct 2009
Posts: 4

PostPosted: Fri Oct 23, 2009 12:42 am    Post subject: Reply with quote

thank you so much
your code is much easier >.<
_________________
;
;;
;';.
; ;;
; ;;
; ;;
; ;;
; ;'
; '
,;;;,;
;;;;;;
`;;;;'
Back to top
View user's profile Send private message
mstorey20



Joined: 21 Sep 2009
Posts: 10

PostPosted: Fri Oct 23, 2009 12:49 am    Post subject: Reply with quote

Code:

StartTime:=A_TickCount            ; Get starting time
ElapsedTime:=A_TickCount-StartTime      ; Just to make sure initialized for while loop

While (ElapsedTime<90000)              ; Loop until your timer hit
{
   Send 1234                            ; Removed your inter key press delays
   Sleep 50                            ; Added some delay before we loop
   ElapsedTime:=A_TickCount-StartTime   ; Calc new time difference
}
Sleep 73500                       ; While broken - sleep
Reload                          ; Reload script

Tested in Notepad -

Edit: this gives more precise control over the total time with such a large number of loops but I like his reset of the counter better than my reload thought.
_________________
StoreyQuickNotes - An AutoHotkey Project for Radiation Oncology
Back to top
View user's profile Send private message
Leef_me



Joined: 08 Apr 2009
Posts: 5336
Location: San Diego, California

PostPosted: Fri Oct 23, 2009 1:29 am    Post subject: Reply with quote

Code:
#SingleInstance, Force ; to force running of a new copy if another is already running
; prevents the msgbox "An older instance of this script is already running.  Replace it with this instance?"

return

F1:: ; start the mashing by pressing F1

run_time= 90000
pause_time = 73500

; this is a 'flag', if set it allows sending of characters
send_char=1

settimer, stop_char, -%run_time%   ; wait 90000 miliseconds, but "run-only-once mode"

loop
{
  if send_char=1
  {
    Send 1234
  }
  Sleep, 150
}

stop_char:
  send_char=0 ; after the timer delay, set the flag to stop characters
  settimer, start_char, -%pause_time%   ; wait 73500 miliseconds , but "run-only-once mode"
return

start_char:
  send_char=1 ; after the timer delay, set the flag to start characters
  settimer, stop_char, -%run_time%   ; wait 90000 miliseconds, but "run-only-once mode"
return



esc::  ; in case of emergency, hit escape key
exitapp
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