Jump to content

Send Problems and Script Stopping


Recommended Posts

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}")

; 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

  • Moderators

KingYoshi,

This has been driving me nuts!

Then I hope this will restore your sanity! ;)

Global $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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 by KingYoshi
Link to comment
Share on other sites

  • Moderators

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 5

My 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 5

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 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 4

I 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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 by KingYoshi
Link to comment
Share on other sites

  • Moderators

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: ;)

#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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 by KingYoshi
Link to comment
Share on other sites

  • Moderators

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 outputted

Did 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 :D) 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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...