Jump to content
Sign in to follow this  
lolp1

Detecting new lines

Recommended Posts

lolp1

Ok, here is my issue.

From a window using WinGetText, I get something like this:

[3:32:38 PM] text

Every few mintues I get a new line (How ever there is no set time, could be 30 seconds, could be 5 mintues..)

I need a way to be able to detect win a new line comes, maybe use WinGetText in a loop, and some how check how many lines of text there are (But I am not sure how to do that) and when a new line appears, I could then use what ever means I need to log it.

any idea :)?

Share this post


Link to post
Share on other sites
BrettF

Maybe something like???

While 1
    $ctrltext =ControlGetText ("Title", "Text", "CONTROLID")
    If NOT $ctrltext = ControlGetText ("Title", "Text", "CONTROLID") Then
    $ctrltext =ControlGetText ("Title", "Text", "CONTROLID")
        MsgBox (0, "Text Added!", "A new line has been added" &@CRLF &$ctrltext)
        $string = StringSplit ($ctrltext, @LF, 0)
        MsgBox (0, "No. Lines", "The control has "&$arrau[0]&" lines.")
    EndIf
WEnd

Share this post


Link to post
Share on other sites
lolp1

Hey, thanks for the idea, I changed it a bit to this:

AutoItSetOption("WinDetectHiddenText", 1)
While 1
    $ctrltext = WinGetText("O_O", "")
    If  $ctrltext <> WinGetText("O_O", "") Then
    $ctrltext =WinGetText("O_O", "")
        MsgBox (0, "Text Added!", "A new line has been added" &@CRLF &$ctrltext)
        $string = StringSplit ($ctrltext, @LF, 0)
        MsgBox(0,"Lol",$string)
        Sleep(30)
    EndIf
WEnd

It works ! It detects when a new line is added. Now the last part I need is to be able to msgbox the text of the line that was added, I tried the above code but did not work, any idea on how I could get the second message box come with the last line of text that was detected?

Edited by lolp1

Share this post


Link to post
Share on other sites
xcal

This part...

$string = StringSplit ($ctrltext, @LF, 0)

...will create an array out of $string. Your message box will look something like MsgBox(0, '', $string[$string[0]]). That gives you the last element of the array, which will presumably be the new text.

Share this post


Link to post
Share on other sites
lolp1

This part...

$string = StringSplit ($ctrltext, @LF, 0)

...will create an array out of $string. Your message box will look something like MsgBox(0, '', $string[$string[0]]). That gives you the last element of the array, which will presumably be the new text.

Well, I tried it like this, and the second msgbox was still completely empty .. I'm not sure why, perhaps you can fill me in?

AutoItSetOption("WinDetectHiddenText", 1)

While 1
    $ctrltext = If  $ctrltext <> WinGetText("O_O", "") Then", "")
    If  $ctrltext <> If  $ctrltext <> WinGetText("O_O", "") Then", "") Then
    $ctrltext =WinGetText("If  $ctrltext <> WinGetText("O_O", "") Then", "")
        MsgBox (0, "Text Added!", "A new line has been added" &@CRLF &$ctrltext)
        $string = StringSplit ($ctrltext, @LF, 0)
       MsgBox(0, '', $string[$string[0]])
        Sleep(30)
    EndIf
WEnd
Edited by lolp1

Share this post


Link to post
Share on other sites
lolp1

I am re-posting as I don't believe I was as clear as I should have been.

Ok, so we have this code here:

AutoItSetOption("WinDetectHiddenText", 1)

While 1
    $ctrltext = WinGetText("O_O...", "")
    If  $ctrltext <> WinGetText("O_O....", "") Then
    $ctrltext =WinGetText("O_O....", "")
        MsgBox (0, "Text Added!", "A new line has been added" &@CRLF &$ctrltext)
        $string = StringSplit ($ctrltext, @LF, 0)
        MsgBox (0, "No. Lines", "The control has " & $string[0] & " lines.")
        Sleep(30)
    EndIf
WEnd

This does: Detects if a new line on that window comes up, if it does it will notify me. Ok, great!

Then it will notify me how many lines of text there is. The main thing I need to do here now, is obtain the text of the new line(s) it detects !

So... lets say: Detected a new line, now has 455 lines, I need also to be able to get what he text is on the new line.

Examle: Detected a new line, now has 455 lines, the new line detected was "Hello" is the type of output I need.

Share this post


Link to post
Share on other sites
PsaltyDS

How about:

MsgBox (0, "No. Lines", "The control has " & $string[0] & " lines." & @CRLF & "Last line: " & $string[$String[0]])

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
PsaltyDS

I decides to make a new thread, seign as the problem my old thread was about was solved.

To make things clear, my end goal here is to detect a new line, how many lines there were, and what the last line detected was !

So far I've got steps one and two. The code below detects a new line on the window, then tells me how many lines there are, the problem is I need to find out how to get the text of the new line it detected. (So the out put looks something like: "New line found, now X amount of lines, last line detected was: Hello".

Any suggestions on how to do this, much appreciated.

EDIT: I seen the reply below to try:

MsgBox (0, "No. Lines", "The control has " & $string[0] & " lines." & @CRLF & "Last line: " & $string[$String[0]])
How ever, this still returns a blank line. I tried it like this DOUBLE EDIT: Just to make sure it was actualy returning text, I also added a Clipput($ctrltext) into the code, and pasted it in note pad, the last line of text was defiantly there, althogh the message box turned up plain :D

AutoItSetOption("WinDetectHiddenText", 1)

While 1
    $ctrltext = WinGetText("[gvbaals, online in channel op vala] - StealthBot v2.6 Revision 3", "")
    If  $ctrltext <> WinGetText("[gvbaals, online in channel op vala] - StealthBot v2.6 Revision 3", "")  Then
    $ctrltext =WinGetText("[gvbaals, online in channel op vala] - StealthBot v2.6 Revision 3", "")
        MsgBox (0, "Text Added!", "A new line has been added" & @CRLF & $ctrltext)
        Sleep(2000)
        $string = StringSplit ($ctrltext, @LF, 1)
        MsgBox (0, "No. Lines", "The control has " & $string[0] & " lines." & @CRLF & "Last line: " & $string[$String[0]])
        Sleep(30)
    EndIf
WEnd

Original code:

AutoItSetOption("WinDetectHiddenText", 1)

While 1
    $ctrltext = WinGetText("O_O...", "")
    If  $ctrltext <> WinGetText("O_O....", "") Then
    $ctrltext =WinGetText("O_O....", "")
        MsgBox (0, "Text Added!", "A new line has been added" &@CRLF &$ctrltext)
        $string = StringSplit ($ctrltext, @LF, 0)
        MsgBox (0, "No. Lines", "The control has " & $string[0] & " lines.")
        Sleep(30)
    EndIf
WEnd
To walk through the string split array from bottom-up looking for non-blank line:

$string = StringSplit ($ctrltext, @LF, 1)
        For $n = $string[0] To 1 Step -1
            If StringStripWS($string[$n]) <> "" Then
                MsgBox (0, "No. Lines", "The control has " & $string[0] & " lines." & @CRLF & "Last non-blank line: " & $string[$n])
                ExitLoop
            EndIf
        Next

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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  

×