KingYoshi Posted July 5, 2011 Share Posted July 5, 2011 I have been working on this and have asked multiple questions about this program over the last couple days. (I keep working on it then stopping and continuing later on) Problems: #1 The script keeps stopping after printing a message only once #2 The script is ignoring the second {Enter} in Send("{Enter}/1" & $Msg1 & " {Enter}") expandcollapse popup; Press Esc to terminate script ; Press Pause to pause the script ; Random Sendkeydelay FileReadLine FileOpen Global $UnPaused, $Keypause, $Delay, $file, $Msg1 HotKeySet("{PAUSE}", "TogglePause") HotKeySet("{ESC}", "Terminate") $file = FileOpen("message.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error 1", "Unable to open file.") Exit EndIf While 1 Sleep(100) ToolTip("Paused",0,0) WEnd Func TogglePause() $UnPaused = NOT $UnPaused While $UnPaused ToolTip("Sending...",0,0) $Keypause = Random(1, 5, 1) AutoItSetOption("SendKeyDelay", $Keypause) $Keypause = Random(1, 5, 1) AutoItSetOption("SendKeyDownDelay", $Keypause) $Msg1 = FileReadLine($file) If @error Then MsgBox(0, "Error 2", "Unable to read file.") FileClose($file) ExitLoop EndIf Send("{Enter}/1" & $Msg1 & " {Enter}") $Delay = Random(5000, 6000, 1) Sleep($Delay) ;Insert copies HERE of above 5 lines for more messages WEnd EndFunc Func Terminate() Exit EndFunc Link to comment Share on other sites More sharing options...
KingYoshi Posted July 6, 2011 Author Share Posted July 6, 2011 This has been driving me nuts! I still am not sure where the problem is. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 6, 2011 Moderators Share Posted July 6, 2011 KingYoshi, This has been driving me nuts!Then I hope this will restore your sanity! expandcollapse popupGlobal $UnPaused = False, $Keypause, $Delay, $file, $Msg1 HotKeySet("{PAUSE}", "TogglePause") HotKeySet("{ESC}", "Terminate") $file = FileOpen("message.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error 1", "Unable to open file.") Exit EndIf ToolTip("Paused",0,0) While 1 Sleep(10) If $UnPaused Then $Keypause = Random(1, 5, 1) ;AutoItSetOption("SendKeyDelay", $Keypause) $Keypause = Random(1, 5, 1) ;AutoItSetOption("SendKeyDownDelay", $Keypause) $Msg1 = FileReadLine($file) If @error Then MsgBox(0, "Error 2", "Unable to read file.") FileClose($file) ExitLoop EndIf ConsoleWrite($Msg1 & @CRLF) ; You should see the lines in the SciTE console <<<<<<<<<<<<<<<<<<<<< ;Send("{Enter}/1" & $Msg1 & " {Enter}") $Delay = Random(5000, 6000, 1) Sleep($Delay) EndIF WEnd Func TogglePause() ; Toggle pause $UnPaused = Not $UnPaused ; Show relevant ToolTip If $UnPaused Then ToolTip("Sending...",0,0) Else ToolTip("Paused",0,0) EndIf EndFunc Func Terminate() Exit EndFunc Toggle $UnPaused outside of the main loop and then action the FileReadLine section only if $UnPaused is set. That way you get the toggle working each time you press the HotKey - the way you had it you were starting new instance of the whole Read/Send function each time you pressed it. I am not sure what your "more messages" comment means - do you want several messages sent before the pause takes effect or do you want the same message sent several times? Either is easy - but which is it? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
KingYoshi Posted July 6, 2011 Author Share Posted July 6, 2011 (edited) Yes I would be sending multiple messages before the pause is sent. Basically: If not paused Send message Send message Send message Loop until Paused But If Toggle Pause is outside of the loop, how would the loop be stopped? Wouldn't it keep loping and never get to TogglePause()? Also, as to my second question, how does this affect the second {Enter} never being sent in the Send Function. Edited July 6, 2011 by KingYoshi Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 6, 2011 Moderators Share Posted July 6, 2011 KingYoshi,That does not really answer the question I asked - but then perhaps I phrased it badly. At the moment you will send the messages (the lines of the file) in succession until the script is paused - once unpaused you recommence sending the lines:Script starts paused Unpause Send Line 1 Send Line 2 Send Line 3 Pause Wait until... Unpause Send Line 4 Send Line 5My question asked if you wanted to send a fixed number of lines before the pause took effect:Script starts paused Unpause Send Line 1 Send Line 2 Pause - but wait until 4 lines have been sent Send Line 3 Send Line 4 Now Pause Wait until... Unpause Send Line 5or whether each line should be sent several times (I have used 3 times as an example here):Script starts paused Unpause Send Line 1 Send Line 1 Send Line 1 Send Line 2 Send Line 2 Send Line 2 Pause Wait until... Unpause Send Line 3 Send Line 3 Send Line 3 Send Line 4 Send Line 4 Send Line 4I think the script I posted does what you want (have you run it to check?) but I was unsure exactly what your "more messages" comment meant. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
KingYoshi Posted July 6, 2011 Author Share Posted July 6, 2011 (edited) or whether each line should be sent several times (I have used 3 times as an example here): Script starts paused Unpause Send Line 1 Send Line 2 Send Line 3 Send Line 4 Send Line 1 Send Line 2 Send Line 3 Send Line 4 Continue indefinitely until Pause is toggled Pause is Toggled Wait until Unpaused is Toggled... Unpause This is exactly what the script should do. I also ran the script but keep getting the Error 2 Unable to read file, error check. It doesn't seem to be able to read the file after it is opened, which is very strange since I then ran my old version again the this was not a problem... (But the old version still had the problems that I originally posted about) Edited July 6, 2011 by KingYoshi Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 6, 2011 Moderators Share Posted July 6, 2011 KingYoshi, Then we take a different approach and load the contents of the file into an array so we can reuse the lines as we wish: expandcollapse popup#include <File.au3> HotKeySet("{PAUSE}", "TogglePause") HotKeySet("{ESC}", "Terminate") Global $UnPaused = False, $Keypause, $Delay, $file, $Msg1 Global $aLines ; Get the lines into an array _FileReadToArray("message.txt", $aLines) ToolTip("Paused",0,0) ; Set a count $iCount = 0 While 1 Sleep(10) If $UnPaused Then $Keypause = Random(1, 5, 1) ;AutoItSetOption("SendKeyDelay", $Keypause) $Keypause = Random(1, 5, 1) ;AutoItSetOption("SendKeyDownDelay", $Keypause) ; Increase the count $iCount += 1 ; Reset to the first line if we have gone past the end of the array If $iCount > $aLines[0] Then $iCount = 1 EndIf ; Read the line $Msg1 = $aLines[$iCount] ConsoleWrite($Msg1 & @CRLF) ; You should see the lines in the SciTE console <<<<<<<<<<<<<<<<<<<<< ;Send("{Enter}/1" & $Msg1 & " {Enter}") $Delay = Random(5000, 6000, 1) Sleep($Delay) EndIF WEnd Func TogglePause() ; Toggle pause $UnPaused = Not $UnPaused ; Show relevant ToolTip If $UnPaused Then ToolTip("Sending...",0,0) Else ToolTip("Paused",0,0) EndIf EndFunc Func Terminate() Exit EndFunc Please ask if you have any questions. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
KingYoshi Posted July 6, 2011 Author Share Posted July 6, 2011 (edited) To be honest I have not worked much with arrays. However I do understand what an array is and its basic functions. Would it be correct to say that currently there is a loop that goes from line 1 - last line, and the loop increases the count by 1 each loop thus going through each line in the text file? If I wanted to just send line 3 to the array I would set $iCount to 3? Just trying to better understand the code you wrote I also tried running your program, however it did nothing... I didn't receive any errors but no text was outputted.. I could still Pause and unpause and press escape to exit, but other then that it was forever sending nothing. Side Question: Also since you used: #include <File.au3>, would this program not run on a computer that didn't have Autoit installed on it? Edited July 6, 2011 by KingYoshi Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 6, 2011 Moderators Share Posted July 6, 2011 KingYoshi, Would it be correct to say that currently there is a loop that goes from line 1 - last line, and the loop increases the count by 1 each loop thus going through each line in the text file?Exactly! If I wanted to just send line 3 to the array I would set $iCount to 3?Setting $iCount to 3 would Send line 3 of the array. however it did nothing [...] no text was outputtedDid you run it from SciTE? I replaced your Send commands with a ConsoleWrite which, so if you did (as it mentioned in the script): ; You should see the lines in the SciTE console <<<<<<<<<<<<<<<<<<<<< If you comment the ConsoleWrite line and uncomment the Send line you get what you originally intended. would this program not run on a computer that didn't have Autoit installed on it?If you compile the script, it will include (as the directive name suggests ) the appropriate file in the script. If you do not compile, then the script will not run at all if AutoIt is not installed. All clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
KingYoshi Posted July 6, 2011 Author Share Posted July 6, 2011 All clear? Yes! And thank you very much for taking so much time to explain all the changes for me. You have been a great 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