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 

How to create a Loop Bypass Timer?

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



Joined: 21 May 2008
Posts: 11

PostPosted: Tue May 27, 2008 3:25 am    Post subject: How to create a Loop Bypass Timer? Reply with quote

Hi, I have searched these forums all day for a method whereby I can create a script which will allow me to mash a button (the "w" key) which will send "1" and then send "2". However, after sending "1" it will not send it again until one minute has elapsed, otherwise it will simply bypass it and send "2" every time the "w" key is mashed until the timer expires. I don't see a native function for this so I assume I will have to grab the current time, convert it to seconds, assign it to a variable and continually check it via a calculation to see if the 60 seconds have elapsed since "1" was first pressed.

I am relatively new at this. Am I correct in my thinking or is there another better way to do this? If anyone could direct me to a script that accomplishes something similar it would be greatly appreciated.

Thanks


Last edited by culliganator on Wed May 28, 2008 1:03 am; edited 1 time in total
Back to top
View user's profile Send private message
Guest






PostPosted: Tue May 27, 2008 7:25 am    Post subject: Reply with quote

Code:
1::
  If Waiting
    Return
  Send 1 ;or whatever you want it to do
  Gosub, StartWait
Return

StarWait:
  Waiting := 1
  Sleep 60000
  Waiting := 0
Return
Back to top
Guest






PostPosted: Tue May 27, 2008 8:32 am    Post subject: Reply with quote

or this
Code:
#MaxThreadsPerHotkey 1
1::
Do Something
Sleep, 60000
Return
Back to top
culliganator



Joined: 21 May 2008
Posts: 11

PostPosted: Tue May 27, 2008 10:34 pm    Post subject: Reply with quote

Thanks a lot. I will try this out and see how it goes.

Edit:
I tried it but I can't seem to get "2" to fire immediatly when "1" is on cooldown. It still waits the 10 seconds which is no different than if I had placed the sleep imediatly after the "send, 1" rather than using the subroutine. Is there a way to make this run in its own thread so that the timer countsdown without affecting the main script?

Oh and to clarify, I want to mash a single button separate from the number keys I am firing. I want to press "w" for example and have it fire "1" and "2" respectively. (I updated my original post to clarify this better)
Back to top
View user's profile Send private message
culliganator



Joined: 21 May 2008
Posts: 11

PostPosted: Wed May 28, 2008 6:06 pm    Post subject: Reply with quote

I am thinking I need to do this with a counter and then figure out aproximately how many iterations match 60 seconds.
Back to top
View user's profile Send private message
JHeikkilaJr



Joined: 24 May 2008
Posts: 6

PostPosted: Thu May 29, 2008 5:28 am    Post subject: Reply with quote

Here's how I do it.

Code:

Timer1 := 60000
Start1 := 0
End1 := 0
Diff1 := 0


followed by:
Code:


pressingkeys:
  End1 := A_TickCount
  Diff1 := End1 - Start1

  if (Diff1 >= Timer1)
  {
     Send, 1
     Start1 := End1
  }
return



Note: The code above is just an example from what I do, you'll have to tweak to meet your specs...

Regards,



[/code]
Back to top
View user's profile Send private message
Slanter



Joined: 28 May 2008
Posts: 307
Location: Minnesota, USA

PostPosted: Thu May 29, 2008 6:30 am    Post subject: Reply with quote

Add this to the beginning of each hotkey
Code:
   If (A_TickCount - Timer%A_ThisHotkey% < 60000
    && Timer%A_ThisHotkey%)
      Return
   Timer%A_ThisHotkey% := A_TickCount


Example
Code:
1::
   If (A_TickCount - Timer%A_ThisHotkey% < 60000
    && Timer%A_ThisHotkey%)
      Return
   Timer%A_ThisHotkey% := A_TickCount
   ; Do stuff after this
   MsgBox 1
Return

2::
   If (A_TickCount - Timer%A_ThisHotkey% < 60000
    && Timer%A_ThisHotkey%)
      Return
   Timer%A_ThisHotkey% := A_TickCount
   ; Do stuff after this
   MsgBox 2
Return


Last edited by Slanter on Thu May 29, 2008 7:51 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Lexikos



Joined: 17 Oct 2006
Posts: 2592
Location: Australia, Qld

PostPosted: Thu May 29, 2008 7:39 am    Post subject: Reply with quote

Code:
w::
    if (!t1 || A_TickCount-t1 > 60000) {
        t1 := A_TickCount
        Send 1
    } else
        Send 2
return
Back to top
View user's profile Send private message
Zed Gecko



Joined: 23 Sep 2006
Posts: 98

PostPosted: Thu May 29, 2008 8:43 am    Post subject: Reply with quote

even shorter Very Happy
Code:
w::
send, % (!t1 || A_TickCount-t1 > 60000) ? 1 : 2
t1 := (!t1 || A_TickCount-t1 > 60000) ? A_TickCount : t1
return

_________________
1) All my code can be reused in ANY way. 2) Please check the help and the forum-search, before posting questions; the answer is out there...
Back to top
View user's profile Send private message
Zed Gecko



Joined: 23 Sep 2006
Posts: 98

PostPosted: Thu May 29, 2008 8:55 am    Post subject: Reply with quote

and as one-liner Cool
Code:
w::send, % (!t1 || A_TickCount-t1 > 60000) ? ((t1 := A_TickCount) ? 1 : 1) : 2

_________________
1) All my code can be reused in ANY way. 2) Please check the help and the forum-search, before posting questions; the answer is out there...
Back to top
View user's profile Send private message
culliganator



Joined: 21 May 2008
Posts: 11

PostPosted: Thu May 29, 2008 5:19 pm    Post subject: Reply with quote

Wow, great responses guys. Now to see if I can get this thing going. I will post what I have when I get it running.

Thanks.
Back to top
View user's profile Send private message
culliganator



Joined: 21 May 2008
Posts: 11

PostPosted: Thu May 29, 2008 6:14 pm    Post subject: Reply with quote

Here is what I have. It works great. If anyone thinks they can shorten it that would be fantastic.

Code:

[::

  { 
    if (!t1 || A_TickCount-t1 > 16000) {
        t1 := A_TickCount
        SendInput  9
        Sleep 250
    } else

    if (!t2 || A_TickCount-t2 > 61000) {
        t2 := A_TickCount
        SendInput 1
        Sleep 2000
    } else

    if (!t3 || A_TickCount-t3 > 30000) {
        t3 := A_TickCount
        SendInput {Alt Down}
        SendInput 1
        SendInput {Alt Up}
        SendInput 0
        Sleep 2000
        SendInput {Home}
        Sleep 2700
    } else

    if (!t4 || A_TickCount-t4 > 19000) {
        t4 := A_TickCount
        SendInput {Alt Down}
        SendInput 2
        SendInput {Alt Up}
        SendInput {Ins}
        Sleep 2000
        SendInput {Home}
        Sleep 2000
    } else

    if (!t5 || A_TickCount-t5 > 13000) {
        t5 := A_TickCount
        SendInput {Alt Down}
        SendInput 3
        SendInput {Alt Up}
        SendInput {Ins}
        Sleep 3000
    } else

    if (!t6 || A_TickCount-t6 > 14000) {
        t6 := A_TickCount
        SendInput {Alt Down}
        SendInput 4
        SendInput {Alt Up}
        SendInput 0
        Sleep 2300
        SendInput {Home}
        Sleep 2500
    } else

    if (!t7 || A_TickCount-t7 > 13000) {
        t7 := A_TickCount
        SendInput {Alt Down}
        SendInput 5
        SendInput {Alt Up}
        SendInput {Home}
        Sleep 2300
    } else

  GetKeyState, state, w,
    if State = U
    break

return



Last edited by culliganator on Wed Sep 03, 2008 12:33 am; edited 17 times in total
Back to top
View user's profile Send private message
Z Gecko
Guest





PostPosted: Thu May 29, 2008 8:00 pm    Post subject: Reply with quote

Quote:
It works great.

Really? Most people will probably think your keyboard is broken, when you run that script. Very Happy
What do you need this for? I canīt think of a use for this. Confused
Back to top
culliganator



Joined: 21 May 2008
Posts: 11

PostPosted: Thu May 29, 2008 8:46 pm    Post subject: Reply with quote

Z Gecko wrote:
What do you need this for? I canīt think of a use for this. Confused


This is for a game where I can mash a button and constantly fire off abilities in a certain order. Each ability has a cooldown of varying lengths so I don't want to fire those or have to wait but rather just move on to the next one. Each ability has an animation which takes a few seconds to complete so that is what the "sleeps" are for. The way it is working now I have the option to either mash the key or just hold it down.
(I may have to change the "w" key to something else or, like you said, it might even seem broken to me if I have to bring up chat and can't type a "w".)


Last edited by culliganator on Fri May 30, 2008 12:53 am; edited 1 time in total
Back to top
View user's profile Send private message
JHeikkilaJr



Joined: 24 May 2008
Posts: 6

PostPosted: Thu May 29, 2008 11:24 pm    Post subject: Reply with quote

Quote:
(I may have to change the "w" key to something else or, like you said, it might even seem broken to me if I have to bring up chat and can't type a "w".)


I get around that with another hot-key that "pauses" the checks.

Code:

$^#P::
  PauseScript := (PauseScript == "NO") ? "YES" : "NO"
return



and then in the actual hot-key procedure I add a check for PauseScript

Code:

  ; If we're paused, ignore the hotkey...
  if (PauseScript == "YES")
    return


Regards
[/quote]
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   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