AutoHotkey Community

It is currently May 24th, 2012, 2:19 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: DelaySend()
PostPosted: October 20th, 2011, 12:04 am 
Offline

Joined: August 29th, 2011, 10:35 pm
Posts: 30
Location: Tokyo
My video player application discards keystrokes sent too quickly so I made this.

DelaySend(Key, Interval=200, SendMethod="Send")
Code:
DelaySend(Key, Interval=200, SendMethod="Send") {
    static KeyStack := []
    KeyStack[Key] := IsObject(KeyStack[Key]) ? KeyStack[Key] : {base: {LastTickCount: 0}}
    ObjInsert( KeyStack[Key], { Key: Key, Interval: Interval, SendMethod: SendMethod })
    Gosub, Label_DelaySend
    Return   
   
    Label_DelaySend:
        For Key in KeyStack {
            if !(MinIndex := KeyStack[Key].MinIndex())
                Continue
            Span := A_TickCount - KeyStack[Key].LastTickCount
            if (Span < KeyStack[Key][MinIndex].Interval)    ;loaded too early
                SetTimer,, % -1 * (KeyStack[Key][KeyStack[Key].MinIndex()].Interval - Span)
            else {
                SendMethod := KeyStack[Key][MinIndex].SendMethod
                SendingKey := KeyStack[Key][MinIndex].Key
                if (SendMethod = "SendInput")
                    SendInput, % SendingKey
                Else if (SendMethod = "SendPlay")
                    SendPlay, % SendingKey
                Else if (SendMethod = "SendRaw")
                    SendRaw, % SendingKey
                Else if (SendMethod = "SendEvent")
                    SendEvent, % SendingKey
                Else
                    Send, % SendingKey

                ObjRemove(KeyStack[Key], MinIndex)    ;decrement other elements
                if KeyStack[Key].MinIndex() ;if there is a next queue
                    SetTimer,, % -1 * KeyStack[Key][KeyStack[Key].MinIndex()].Interval
                KeyStack[Key].base.LastTickCount := A_TickCount
            }
        }
    Return
}

Examples:
Code:
$a::DelaySend("a", 1500)
$s::DelaySend("s", 500)
$d::DelaySend("d", 200, "SendInput")
Code:
^Right::DelaySend("{Media_Next}", 500)
^Left::DelaySend("{Media_Prev}", 500)

It requires AutoHotkey_L. 1.1.01 or later. The details are found in the links.

_________________
English teachers are welcome.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2011, 8:17 pm 
Offline

Joined: September 17th, 2005, 6:43 pm
Posts: 242
Code:
DelaySend(Key, Interval=200, SendMethod="Send"){
 find=1
 loop
 {
  x:=substr(key,find,1)
  if x=`{
  regexmatch(key,"U)({.*})",found,find),find:=find+strlen(found1)-1,x:=found1
  find++
  sleep,%interval%
  if (SendMethod = "SendInput")
  SendInput, % x
  Else if (SendMethod = "SendPlay")
  SendPlay, % x
  Else if (SendMethod = "SendRaw")
  SendRaw, % x
  Else if (SendMethod = "SendEvent")
  SendEvent, % x
  Else
  Send, % x
  if !x
  break
 }
}
+a::DelaySend("a{home}c{end}t",1500)

Not too sure if this is what you were doing but I thought I would give it a shot.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2011, 11:12 pm 
My function remembers the passed keys so if you tap the a key three times quickly in the following example, the character "a" will be sent three times with the given interval while yours sends only one time.
Code:
$a::DelaySend("a",500)

The media player I'm using skips 15 seconds by pressing the {media_next} button. Because it responds slowly, if I want to skip 45 seconds and press the button three times quickly, it just skips 15 seconds accepting only one key input. So the function comes handy in such situation.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: jsquard, maraskan_user, RaptorX and 22 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group