VerteXslaPPy Posted August 11, 2015 Share Posted August 11, 2015 Hello all, for example i have a script : #include <*.au3> While 1 Adlibregister("messageBx",1) WEnd Func MessageBx() if _isPressed($H)Then Do this for 2secconds ConsoleWrite("Hello !") when the 2 secconds are over it should stop until i will press $H again Endfunci saw something about a timer function but this didnt helped me alot because it was always spamming Hello ! again again again it didnt stoped, i want that the Function stop after the 2secconds even if i hold H, it should first restart the 2secconds if i release H and press it again would be verry nice if some one can help me up. Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted August 11, 2015 Share Posted August 11, 2015 Adlibregster() should be called only one time and it will repeat on its own at the defined time. Your going to be registering it over and over and over in a loop (with no delay at that)That is just for starters. Link to comment Share on other sites More sharing options...
VerteXslaPPy Posted August 11, 2015 Author Share Posted August 11, 2015 Delay will dont change anything of the speed from the script? also its impossible to do what i want? Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted August 11, 2015 Share Posted August 11, 2015 I am not sure what you want exactly.You want a hotkey to launch a function.Is that function supposed to only run one time in 2 seconds or over and over again for 2 seconds?It may be better that you give us real life examples of what you want to do rather than theory.Why do you need _IsPressed() ? do you want the function to stop if you let go of the key? Link to comment Share on other sites More sharing options...
VerteXslaPPy Posted August 11, 2015 Author Share Posted August 11, 2015 I am not sure what you want exactly.You want a hotkey to launch a function.Is that function supposed to only run one time in 2 seconds or over and over again for 2 seconds?It may be better that you give us real life examples of what you want to do rather than theory.Why do you need _IsPressed() ? do you want the function to stop if you let go of the key? no i use if pressed because : when i press H it should write in the console for 3secconds this word Hello so here what i do with my hands press H (and hold it) it spams 3secconds Hello in the console,(im still holding H) it stop spamming(im still holding H......) now i release H, press H again (and hold it) it spams 3secconds Hello in the console,(im still holding H) it stop spamming(im still holding H......) now i release H, press H again sorry my english is verry bad but i hope you understand it now Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted August 11, 2015 Share Posted August 11, 2015 This is mostly working, the pres and hold works great but the on release is a big slow to take effect. probably a much better way to do this but you can at least verify this is kind of what your trying to do and a better code writing can give you a proper solution. #Include <Misc.au3> HotKeySet("H", "Loop") While 1 Sleep(10) WEnd Func Loop() HotKeySet("H") $vStart = TimerInit() While 1 If _ISPressed("48", 'user32.dll') Then ConsoleWrite(@CRLF & "Function Running" & @CRLF & "$vStart = " & $vStart & @CRLF & "TimerDiff = " & TimerDiff($vStart) & @CRLF) If TimerDiff($vStart) > 200 Then ExitLoop Else ExitLoop EndIf WEnd While 1 If _ISPressed("48", 'user32.dll') Then Sleep(10) Else ExitLoop EndIf WEnd HotKeySet("H", "Loop") EndFunc Link to comment Share on other sites More sharing options...
VerteXslaPPy Posted August 11, 2015 Author Share Posted August 11, 2015 thanks buddy this helped me a littlebit ! If TimerDiff($vStart) > 200 Then ExitLoop about this ExitLoop is ending the While 1, is there something diferent expect ExitLoop to exit a function? Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted August 11, 2015 Share Posted August 11, 2015 ExitLoop exits the current loop, if its a Function you can use Return, and there is alwasy Exit to exit the entire script.I used Exitloop in that first loop to take you into a second loop that stops the function if your still holding the hotkey. Not until you release the hotkey is the second loop exited, and upon exit it reasigns the hotkey so that you can launch the function again. VerteXslaPPy 1 Link to comment Share on other sites More sharing options...
JohnOne Posted August 11, 2015 Share Posted August 11, 2015 2000 is 2 seconds. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted August 11, 2015 Share Posted August 11, 2015 Yeah 2000 milliseconds, but the crazy code I came up with is not accurate and 200 was much closer to 2 seconds than 2000. 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