Line Posted January 25, 2014 Share Posted January 25, 2014 Hey, I'm new to AutoIT scripting and I'm trying to create a small auto-action that writes something for me in notepad. I choose what to write and the delay time. I looked at a tut on the web on doing it but the problem is that the actions kinda are impossible to stop. If I press the start button and the words are wrote in notepad,I can't press the "x" button on the bot. http://puu.sh/6xunS/433f129c4d.jpg <Image And this is the code: #include <GUIConstantsEx.au3> GUICreate("Konrad Story Teller",335,100) GUICtrlCreateLabel("Word",8,10) $key1 = GUICtrlCreateInput("",35,8,120) GUICtrlCreateLabel("Time",8,44) $time1 = GUICtrlCreateInput("",35,40,120) $startbutton = GUICtrlCreateButton ("Start",190,8,60) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $startbutton $send1 = GUICtrlRead($key1) $sleep1 = GUICtrlRead($time1) While 1 Send($send1) Sleep($sleep1) WEnd Case $msg = $GUI_EVENT_CLOSE GUIDelete() ExitLoop EndSelect WEnd Link to comment Share on other sites More sharing options...
Inverted Posted January 25, 2014 Share Posted January 25, 2014 (edited) It's better to use hotkeys to start/stop so you don't have to switch between windows and have stuff written all over. I've made it like this : First you save your settings, then you use CTRL+F1 to start sending and CTRL-F2 to stop sending. Also, the time is multiplid by 1000 so it's in seconds, not milliseconds. expandcollapse popup#include <GUIConstantsEx.au3> GUICreate("Konrad Story Teller",335,100) GUICtrlCreateLabel("Word",8,10) $key1 = GUICtrlCreateInput("",35,8,120) GUICtrlCreateLabel("Time",8,44) $time1 = GUICtrlCreateInput("",35,40,120) $startbutton = GUICtrlCreateButton ("Save",190,8,60) GUISetState(@SW_SHOW) Global $keepSending = False Global $send1 = "" Global $sleep1 = 0 HotKeySet("^{F1}","startSending") HotKeySet("^{F2}","stopSending") While 1 $msg = GUIGetMsg() Select Case $msg = $startbutton $send1 = GUICtrlRead($key1) $sleep1 = GUICtrlRead($time1)*1000 Case $msg = $GUI_EVENT_CLOSE GUIDelete() ExitLoop EndSelect WEnd Func startSending() $keepSending = True While $keepSending Send($send1) Sleep($sleep1) WEnd EndFunc Func stopSending() $keepSending = False EndFunc Edited January 25, 2014 by Inverted Link to comment Share on other sites More sharing options...
Unc3nZureD Posted January 25, 2014 Share Posted January 25, 2014 Have a look at your while loop. While 1 Send($send1) Sleep($sleep1) WEnd Here you are not checking anything what happens on your gui. You have te re-add a check for your the exit button like here: While 1 Send($send1) Sleep($sleep1) Local $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then Exit ;GUIDelete() ;ExitLoop EndIf WEnd (Sorry for the messy code, my editor on the forum is bugged, I can't use BB tags) Link to comment Share on other sites More sharing options...
Line Posted January 25, 2014 Author Share Posted January 25, 2014 (edited) Thanks alot Unc3nZureD Edit: So if I would want to put a pause button,must I add this? While 1 Send($send1) Sleep($sleep1) Local $msg = GUIGetMsg() If $msg = $pausebutton Then Sleep(1) ;GUIDelete() ;ExitLoop EndIf WEnd Edited January 25, 2014 by Baetu Link to comment Share on other sites More sharing options...
Unc3nZureD Posted January 26, 2014 Share Posted January 26, 2014 (edited) I can't see the point of a pause button A stop button would be easier, and in your current project it would be enough If $msg = $stopbutton Then Exitloop This way it stops, and he can press the start again. Edited January 26, 2014 by Unc3nZureD Link to comment Share on other sites More sharing options...
Inverted Posted January 26, 2014 Share Posted January 26, 2014 You don't like my code ?  Link to comment Share on other sites More sharing options...
Line Posted January 26, 2014 Author Share Posted January 26, 2014 No no Inverted,its awesome,its just that I don't currently want to press keys to activate it.I could have used winwait for my notepad so the text won't be written all over. Another question for you guys: If I would delete the label "time" there and the input from it.And modify a bit the code to make my little program a bot to set any window I want on top,how would I make the WinSetOnTop command read what the user writes? This is the modified version of the upper script: #include <GUIConstantsEx.au3> GUICreate("Konrad's:Always On Top",335,100) GUICtrlCreateLabel("Window Title:",8,10) $win = GUICtrlCreateInput("",35,8,120) $startbutton = GUICtrlCreateButton ("TopIT",190,8,60) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $startbutton $win1 = GUICtrlRead($win) While 1 WinSetOnTop($win1) ; ?????? WEnd Case $msg = $GUI_EVENT_CLOSE GUIDelete() ExitLoop EndSelect WEnd Link to comment Share on other sites More sharing options...
Unc3nZureD Posted January 26, 2014 Share Posted January 26, 2014 Why don't you use ControlSend? That way you can send the text DIRECTLY to the desired window, even if it's not on the top. Link to comment Share on other sites More sharing options...
Line Posted January 26, 2014 Author Share Posted January 26, 2014 (edited) Can I use ControlSend with the text got from a input as example? Piece of code: $input = GUICtrlCreateInput("",x,y) $startbt = GUICtrlCreateButton("",x,y,z,w) While 1 $msg = GUIGetMsg() Select Case $msg = $startbt $input1 = GUICtrlRead($input) While 1 ControlSend($input1,"","Edit","RandomText") Edited January 26, 2014 by Line Link to comment Share on other sites More sharing options...
Unc3nZureD Posted January 26, 2014 Share Posted January 26, 2014 Yes, you can If ControlSend($input1,"","Edit","RandomText") isn't working, you can still send this: ControlSend($input1, "", "", "RandomText") Link to comment Share on other sites More sharing options...
Line Posted January 26, 2014 Author Share Posted January 26, 2014 Thanks for the help 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