Jump to content

func() help


Recommended Posts

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?

Link to comment
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
Link to comment
Share on other sites

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...