dougal88 Posted November 25, 2016 Share Posted November 25, 2016 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 More sharing options...
InunoTaishou Posted November 25, 2016 Share Posted November 25, 2016 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 dougal88 1 Link to comment Share on other sites More sharing options...
iamtheky Posted November 25, 2016 Share Posted November 25, 2016 (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 November 25, 2016 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
dougal88 Posted November 25, 2016 Author Share Posted November 25, 2016 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! Link to comment Share on other sites More sharing options...
kylomas Posted November 25, 2016 Share Posted November 25, 2016 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now