Sign in to follow this  
Followers 0
dougal88

Throttle key press rate

5 posts in this topic

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



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

 

1 person likes this

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

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

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

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