Jump to content
Sign in to follow this  
dougal88

Throttle key press rate

Recommended Posts

dougal88

Hi

I'm just learning autoit and was trying a simple idea to throttle how fast someone can press a key.

HotKeySet("{SPACE}", "captureSpace")

Func captureSpace()
         HotKeySet("{SPACE}")
         Send("{SPACE}")
         HotKeySet("{SPACE}", "captureSpace")
EndFunc

 

How would I stop someone pressing space bar more than once a second even if they were thrashing the key?  I thought this would be simple but my attemps at introducing TimerDiff() have not worked.  Thank you for any pointers!

Share this post


Link to post
Share on other sites
InunoTaishou
HotKeySet("{SPACE}", "captureSpace")

Local $iTimer = TimerInit()

While (True)
    Sleep(100)
WEnd

Func captureSpace()
    If (TimerDiff($iTimer) >= 1000) Then
        ConsoleWrite("More than a second passed, allowed" & @CRLF)
        HotKeySet("{SPACE}")
        Send("{SPACE}")
        HotKeySet("{SPACE}", "captureSpace")
        $iTimer = TimerInit()
    Else
        ConsoleWrite("Stop spamming space bar!" & @CRLF)
    EndIf
EndFunc   ;==>captureSpace

 

  • Like 1

Share this post


Link to post
Share on other sites
iamtheky

that logic is off, imho I think you would capture space as you have, only capturespace would...

1) start the timer

2) start a loop

3) set the hotkey for space to a function that does nothing

4) check the timer, if past a second then reset the hotkey back to the capturespace function and exitloop

 

*Inuno's pretty much does that, it's what I get for disabling notifications.

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
dougal88

Thank you for your fast responses.

@InunoTaishou

Thank you, that helped immensely!  I was making a silly mistake now I see what you've done.  That works perfectly.  Thank you also for including the console messaging, it's very useful!

Share this post


Link to post
Share on other sites
kylomas

dougal88,

Do you realize that this will affect all apps running?  Start your script, then notepad and press the space bar.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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.