moneypulation Posted July 31, 2014 Share Posted July 31, 2014 (edited) Hey guys I wanna create a tool I can save time and nerves with. It will press keys for me till I want to stop but that is exactly my problem. I want to create a pause function so I don't have to restart the autoit script again. The script I made looks like this: Func go() Local $hDLL = DllOpen("user32.dll") $ispressed = _IsPressed("51",$hDLL) Do Send("a") Sleep(500) Send("b") Sleep(500) Until $ispressed = 1 DllClose($hDLL) EndFunc But it won't react to my hotkey (Q) and keep writing abababab and so on. So, how can I improve this script? Maybe use another loop? Thanks for helping sincerly, money Edited July 31, 2014 by moneypulation Link to comment Share on other sites More sharing options...
Solution computergroove Posted July 31, 2014 Solution Share Posted July 31, 2014 (edited) HotKeySet("q","TogglePause") Func go() Local $hDLL = DllOpen("user32.dll") While 1 Send("a") Sleep(500) Send("b") Sleep(500) WEnd EndFunc Func TogglePause() ExitLoop $Paused = NOT $Paused While $Paused sleep(100) ToolTip('Script is "Paused"',350,0) WEnd ToolTip("") DllClose($hDLL) Go() EndFunc Try this. q pauses the script and reregisters user32.dll Why are you registering the user32.dll instead of just doing this: HotKeySet("q","TogglePause") While 1 go() WEnd Func go() Send("a") Sleep(500) Send("b") Sleep(500) WEnd EndFunc Func TogglePause() $Paused = NOT $Paused While $Paused sleep(100) ToolTip('Script is "Paused"',350,0) WEnd ToolTip("") EndFunc Edited July 31, 2014 by computergroove moneypulation 1 Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
moneypulation Posted July 31, 2014 Author Share Posted July 31, 2014 Works like a charm Thanks! Link to comment Share on other sites More sharing options...
olivarra1 Posted July 31, 2014 Share Posted July 31, 2014 Hey guys I wanna create a tool I can save time and nerves with. It will press keys for me till I want to stop but that is exactly my problem. I want to create a pause function so I don't have to restart the autoit script again. The script I made looks like this: Func go() Local $hDLL = DllOpen("user32.dll") $ispressed = _IsPressed("51",$hDLL) Do Send("a") Sleep(500) Send("b") Sleep(500) Until $ispressed = 1 DllClose($hDLL) EndFunc But it won't react to my hotkey (Q) and keep writing abababab and so on. So, how can I improve this script? Maybe use another loop? Thanks for helping sincerly, money ComputerGroove has the solution. Think that in programming languages like these, the computer executes the program line by line, one after the other. So your script what does is first check wether the q key is pressed, and store that result in $ispressed (normally it gets to false) And then it will loop until $ispressed gets to true, but that will be never, since you never set the variable $ispressed again inside that loop. But I think ComputerGroove's solution using HotKeySet is what you are looking for. In that case, you tell AutoIt that whenever "q" is pressed, he should run the function "TogglePause", and in that TooglePause function you just set $paused to the value you want. This "feature" is called an interruption, because it "interrupts" the normal flow of the program, that's line by line. moneypulation 1 Link to comment Share on other sites More sharing options...
somdcomputerguy Posted July 31, 2014 Share Posted July 31, 2014 (edited) Try this too. q starts and stops, ESC quits. Replace the ConsoleWrite's with Send of course, and you dont need the one in the Quit function Local $var HotKeySet("q", "Repeat") HotKeySet("{ESC}", "Quit") Go() Func Go() $var = 0 While 1 Sleep(10) WEnd EndFunc Func Repeat() If $var = 1 Then Go() $var = 1 While 1 ConsoleWrite("a") Sleep(500) ConsoleWrite("b") Sleep(500) WEnd EndFunc Func Quit() ConsoleWrite(@LF) Exit EndFunc I see that I was a bit late.. I posted anyway, since I was done writing the script. Edited July 31, 2014 by somdcomputerguy - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. 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