Jump to content

Throttle key press rate


dougal88
 Share

Recommended Posts

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!

Link to comment
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

 

Link to comment
Share on other sites

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

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

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