Jump to content

LineReader


Hok
 Share

Recommended Posts

Hey,

I'm trying to make a program that reads lines in a program to make a macro. So for example - a text file would contain...

[RandomWait] [5] [10]
[MouseClick] [Right] [30] [60]

The program would output; a random wait from 5 to ten seconds, then a mouseclick. However, I didn't finish and i think I am approaching it wrong... here is my source.

#Include <File.au3>

$FileName = InputBox("File Name", "Input the file name of the script:", "Input Script Name")
FileOpen($FileName, 0)

$NumberLines = _FileCountLines($FileName)
$NumberLines = $NumberLines+1


While $NumberLines>0
    FileReadLine($FileName, $NumberLines = $Numberlines-1)
    
WEnd

- Hok

Link to comment
Share on other sites

With some commented error-checking...

;#include<array.au3>

$message = "Open file containing commands"
$var = FileOpenDialog($message, @ScriptDir, "Command List files (*.lst)", 1)

If Not @error Then
    $file = FileOpen($var, 0)
    ConsoleWrite($var & @tab & $file & @crlf)
    If $file <> -1 Then
        While 1
            $line = FileReadLine($file)
            If @error Then ExitLoop
        ;ConsoleWrite($line & @crlf)
            $line = StringReplace($line,"] [","|")
            $line = StringReplace($line,"]","")
            $line = StringReplace($line,"[","")
            $aLine = StringSplit($line,"|")
        ;_ArrayDisplay($aLine)
            if not @error then
                Switch $aLine[1]
                    Case "RandomWait"
                        ConsoleWrite($aLine[2] & @tab & $aLine[3] & @crlf)
                        Sleep(Random($aLine[2],$aLine[3]) * 1000)
                    Case "MouseClick"
                        ConsoleWrite($aLine[2] & @tab & $aLine[3] & @tab & $aLine[4] & @crlf)
                        MouseClick($aLine[2],$aLine[3],$aLine[4])
                EndSwitch
            endif
        Wend
    EndIf
    FileClose($file)
EndIf


#cs
Filename "command.lst" contains

[RandomWait] [5] [10]
[MouseClick] [Right] [30] [60]

#ce
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...