Sign in to follow this  
Followers 0
Ult902

func() help

4 posts in this topic

ok i have a kotkey set to call a func, which types "a" to make it simple. theres only about 100ms worth of delay in there, but if i hold the hotkey it repeats faster than it should. which is pretty much spamming the func. is there any way to block a func from being called while a func is already running?

Share this post


Link to post
Share on other sites

This should do what you want, I commented everything so you can see what is what (if you didn't already know)

HotKeySet("f", "Function") ;Set the key "f" to call function "Function"

Global $SpamTimer = TimerInit() ;Initialize a timestamp to $SpamTimer

While 1
    Sleep(1000) ;Sleep for 1 second to keep the script running idle while nothing is happening
WEnd

Func Function()
    If TimerDiff($SpamTimer) < 100 Then Return ;Check if the timestamp in $SpamTimer is more than 100ms old, if not, exit the function without doing anything
        Send("a") ;Send the keystroke
        $SpamTimer = TimerInit() ;Put a new timestamp in $SpamTimer
EndFunc

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Nice example.

Thanks :idea:


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  
Followers 0