Jump to content
Sign in to follow this  
Wurschtbrot

Timer

Recommended Posts

Wurschtbrot

well i want to klick some keys every XY Second's

therefor i made a little script:

Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)

WinWait("Unbenannt - Editor","")
If Not WinActive("Unbenannt - Editor","") Then WinActivate("Unbenannt - Editor","")
WinWaitActive("Unbenannt - Editor","")

Global $REDCooldown1 = 1000
Global $REDCooldown1Temp
Global $REDCooldown2 = 2000
Global $REDCooldown2Temp
Global $REDCooldown3 = 3000
Global $REDCooldown3Temp
Global $REDCooldown4 = 4000
Global $REDCooldown4Temp


While 1
If $REDCooldown4 <= TimerDiff($REDCooldown4Temp) Then
    Send("4")
    $REDCooldown4Temp = TimerInit()
EndIf
If $REDCooldown3 <= TimerDiff($REDCooldown3Temp) Then
    Send("3")
    $REDCooldown3Temp = TimerInit()
EndIf
If $REDCooldown2 <= TimerDiff($REDCooldown2Temp) Then
    Send("2")
    $REDCooldown2Temp = TimerInit()
EndIf
If $REDCooldown1 <= TimerDiff($REDCooldown1Temp) Then
    Send("1")
    $REDCooldown1Temp = TimerInit()
EndIf
Sleep(250)
WEnd

of wich i think it will work do i need to set "Global $REDCooldown4Temp = TimerInit()"

or can it be without = TimerInit()

this is simplyfied versin of the original and here i dont have the problem any one noticed that he sends all at once sometimes ? its not like the accidently match the time its more like the time resets or rises irrational and all funcs are clear to go

maybe there is a better way to do it ?

Edited by Wurschtbrot

Share this post


Link to post
Share on other sites
Wurschtbrot

why not

do

send(key)

sleep(1000)

send(new key)

sleep(1000)

send (new key)

sleep(1000)

until 1=0

this is a func i call it when i want one of the keys pressed (wichever one is avalible again ) then as fast as possible return to the old func and continue other stuff

then after all other funcs are colled he calles this one again ....if i use sleep the script will pause! i need it more like simultanius (sametime) to other stuff

i cannot make it into another autoit exe since i only need it sometimes....

with these keys i activate Skills wich have a time Limit (can only be used every 7sec or something ) and i only want to use em as long as i attack the ennemy

Share this post


Link to post
Share on other sites
PsaltyDS

Much better way to do this:

HotKeySet("{ESC}", "_Quit")

Global $REDCooldown1 = 1000
Global $REDCooldown1Temp = TimerInit()
Global $REDCooldown2 = 2000
Global $REDCooldown2Temp = TimerInit()
Global $REDCooldown3 = 3000
Global $REDCooldown3Temp = TimerInit()
Global $REDCooldown4 = 4000
Global $REDCooldown4Temp = TimerInit()

; Open notepad to monitor test
Run("notepad.exe")
WinWait("Untitled - Notepad")
$hWin = WinGetHandle("Untitled - Notepad")
If Not WinActive($hWin) Then WinActivate($hWin)
WinWaitActive($hWin)

; Check timer status every 100ms
AdlibEnable("_TimerDispatch", 100)

; Script could be busy doing other things here...
While 1
    Sleep(20)
WEnd

; Function to perform timed operations
Func _TimerDispatch()
    If $REDCooldown4 <= TimerDiff($REDCooldown4Temp) Then
        ControlSend($hWin, "", "Edit1", "4{ENTER}")
        $REDCooldown4Temp = TimerInit()
    EndIf
    If $REDCooldown3 <= TimerDiff($REDCooldown3Temp) Then
        ControlSend($hWin, "", "Edit1", "3{ENTER}")
        $REDCooldown3Temp = TimerInit()
    EndIf
    If $REDCooldown2 <= TimerDiff($REDCooldown2Temp) Then
        ControlSend($hWin, "", "Edit1", "2{ENTER}")
        $REDCooldown2Temp = TimerInit()
    EndIf
    If $REDCooldown1 <= TimerDiff($REDCooldown1Temp) Then
        ControlSend($hWin, "", "Edit1", "1{ENTER}")
        $REDCooldown1Temp = TimerInit()
    EndIf
EndFunc   ;==>_TimerDispatch

; Function to kill script
Func _Quit()
    Exit
EndFunc   ;==>_Quit

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Wurschtbrot

Much better way to do this:

HotKeySet("{ESC}", "_Quit")

Global $REDCooldown1 = 1000
Global $REDCooldown1Temp = TimerInit()
Global $REDCooldown2 = 2000
Global $REDCooldown2Temp = TimerInit()
Global $REDCooldown3 = 3000
Global $REDCooldown3Temp = TimerInit()
Global $REDCooldown4 = 4000
Global $REDCooldown4Temp = TimerInit()

; Open notepad to monitor test
Run("notepad.exe")
WinWait("Untitled - Notepad")
$hWin = WinGetHandle("Untitled - Notepad")
If Not WinActive($hWin) Then WinActivate($hWin)
WinWaitActive($hWin)

; Check timer status every 100ms

; Function to perform timed operations
Func _TimerDispatch()
    If $REDCooldown4 <= TimerDiff($REDCooldown4Temp) Then
        ControlSend($hWin, "", "Edit1", "4{ENTER}")
        $REDCooldown4Temp = TimerInit()
    EndIf
    If $REDCooldown3 <= TimerDiff($REDCooldown3Temp) Then
        ControlSend($hWin, "", "Edit1", "3{ENTER}")
        $REDCooldown3Temp = TimerInit()
    EndIf
    If $REDCooldown2 <= TimerDiff($REDCooldown2Temp) Then
        ControlSend($hWin, "", "Edit1", "2{ENTER}")
        $REDCooldown2Temp = TimerInit()
    EndIf
    If $REDCooldown1 <= TimerDiff($REDCooldown1Temp) Then
        ControlSend($hWin, "", "Edit1", "1{ENTER}")
        $REDCooldown1Temp = TimerInit()
    EndIf
EndFunc   ;==>_TimerDispatch

; Function to kill script
Func _Quit()
    Exit
EndFunc   ;==>_Quit

:D

omg ! this is perfect for a LOT of things i have to rewrite my whole script XD

if i use it like this :

While 1

blah x

AdlibEnable("_TimerDispatch", 100)

Sleep(20)

msgbox()

AdlibDisable("_TimerDispatch")

Blah y

WEnd

then it would only run the func while sleep 20

and msg box

parallel to the script in between and i guess i can make as many AdlibEnable()'s as i want ? like running 2-3 or more Funcs at once ?

Share this post


Link to post
Share on other sites
PsaltyDS

if i use it like this :

While 1

blah x

AdlibEnable("_TimerDispatch", 100)

Sleep(20)

msgbox()

AdlibDisable("_TimerDispatch")

Blah y

WEnd

then it would only run the func while sleep 20

and msg box

parallel to the script in between and i guess i can make as many AdlibEnable()'s as i want ? like running 2-3 or more Funcs at once ?

No. AutoIt is not multi threaded, and MsgBox() is a "blocking" function. Nothing else will happen while the message box is up:

Global $n = 0
While $n < 5
    AdlibEnable("_TimerDispatch", 100)
    Sleep(20)
    MsgBox(64, "Test", "Test")
    AdlibDisable()
WEnd

Func _TimerDispatch()
    ConsoleWrite("Debug: $n = " & $n & @LF)
    $n += 1
EndFunc

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Wurschtbrot

No. AutoIt is not multi threaded, and MsgBox() is a "blocking" function. Nothing else will happen while the message box is up:

Global $n = 0
While $n < 5
    AdlibEnable("_TimerDispatch", 100)
    Sleep(20)
    MsgBox(64, "Test", "Test")
    AdlibDisable()
WEnd

Func _TimerDispatch()
    ConsoleWrite("Debug: $n = " & $n & @LF)
    $n += 1
EndFunc

:D

damn well i only have 1 input box

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.