Sign in to follow this  
Followers 0
Hok

LineReader

4 posts in this topic

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

Share this post


Link to post
Share on other sites



Thanks...

but I kinda wanted to develop it myself...

- Hok

Share this post


Link to post
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

Share this post


Link to post
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
Sign in to follow this  
Followers 0