Jump to content

How to use more than one callback called periodictly


Recommended Posts

I need to be able to use send command for many keys at periodict time, but it's not the same time for all keys.

For exemple I need to press "a" every 250 ms and "b" every 320 ms,...

I had try to use AdlibEnable function but it works only for the lastest call of it.

I think that I can use a callback called each second and use the mod function to solve the probleme but it's a curious way for me.

Maybe there is an other solution?

Link to comment
Share on other sites

You can just use this:

Func a()
     ;do stuff
     Sleep(250)
EndFunc

Func b()
     ;do stuff
     Sleep(320)
EndFunc

Func c()
     a()
     b()
EndFunc

c()

I am not sure if that was not what you were looking for, but.. there it is!

Edited by sandman

[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Link to comment
Share on other sites

@sandman how do you tink that will play out on the timelin?

I would sugest something like this:

;TimerLib.au3
;
#region - Timer
Global $TimerStorage[10][3]
Global $TimerGo = 0
Func TimerAdd($funcname, $ms)
   dbg("TimerAdd($funcname:=" & $funcname & ", $ms:=" & $ms)
   $ret = $TimerStorage[0][0] + 1
   $TimerStorage[$ret][0] = $funcname
   $TimerStorage[$ret][1] = $ms
   $TimerStorage[$ret][2] = 0
   $TimerStorage[0][0] = $ret
   Return $ret
EndFunc

Func TimerRemove($id)
   $TimerStorage[$id][0] = ""
   $TimerStorage[$id][1] = ""
   $TimerStorage[$id][2] = 0
EndFunc

Func TimerCheck()
   ;;;dbg("TimerCheck::$TimerGo:=" & $TimerGo)
      For $i = 1 to $TimerStorage[0][0]
         If $TimerStorage[$i][0] <> "" Then 
            If $TimerStorage[$i][2] = 0 Then 
               $TimerStorage[$i][2] = TimerInit()
            ElseIf TimerDiff($TimerStorage[$i][2]) >= $TimerStorage[$i][1] Then 
               ;;;dbg("Calling: " & $TimerStorage[$i][0])
               Call($TimerStorage[$i][0])
               $TimerStorage[$i][2] = TimerInit()
            EndIf
         EndIf
      Next 
EndFunc
#endregion - Timer
Func Main()
   HotKeySet("{ESC}", "Terminate")
   TimerAdd("A", 1000)
   TimerAdd("B", 300)
   TimerAdd("C", 33)

   AdLibEnable("TimerCheck", 25)
   While True
      sleep(10)
   WEnd
   Exit
EndFunc
Func Terminate()
   Exit
EndFunc
Func A()
   dbg("A Called")
EndFunc
Func B()
   dbg("B Called")
EndFunc
Func C()
   dbg("C Called")
EndFunc
Func dbg($msg, $line=@ScriptLineNumber, $err=@error, $ext=@extended)
   ConsoleWrite("(" & $line & ") := (" & $err & ")(" & $ext & ") " & $msg & @CRLF)
EndFunc
; ====================
Main()
Exit
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...