Jump to content

Watch for then replace certain text in a richedit chat window


Recommended Posts

OK, as per waters suggestion in my only other thread I'm going to simply ask for help, and find out how wrong I have been going about this...

I am using the program YahELite from http://www.yahelite.org/

It displays its chat text via richedit according to the window info tool http://img696.imageshack.us/img696/7264/63451641.jpg

What I want to do:

I would like to monitor (in realtime) this richedit control and alter the text that is displayed on it.

More specifically I would like to alter user names to custom defined text. The reason for this is that people use multiple names in chat, and it gets annoyingly hard to keep track of a group of ten people all using 5 different names each. I think autoit can help me to create a program that will monitor the window for the text (usernames) I specify, then replace them when they are drawn to my own custom defined text. Eventually I hope to be able to have this program save its settings as well. I am not ready to even begin thinking about how to do all of that, so for now I'm just working my up the scale, so to speak.

What else I want to do:

I want to learn from this script. I want to learn what exactly it is Im doing when I issue these commands. Please don't think of me as rude when I say that I do not want someone to just spoon feed me a completed script. I think I can learn best by taking little bites at a time.

So as of right now, I would like someone to help me simply show the text from that richedit chat window in my own gui. Below is the code I have so far. I know it's very little, but I don't have a clue where to go next, or if I'm even on the right track. I have read and read and read all I can stand. I end up saturated, without a single line more of working code. If anyone does decide to help this poor noob out, please include what exactly it is we are doing in the example you share. Remember, I want to learn, not just be handed the code.

#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <RichEditConstants.au3>

$Form1 = GUICreate("Form1", 339, 233)
$List1 = GUICtrlCreateList("", 8, 8, 321, 214)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    $var = ControlGetText("[CLASS:RichEdit20A]", "text", 1020)
    GUICtrlSetData($List1, $var)
WEnd

Thanks for any help guys.

Link to comment
Share on other sites

Hi TitanRain,

there is is only one small problem with your script.

The line

$var = ControlGetText("[CLASS:RichEdit20A]", "text", 1020)
is wrong.

The first parameter is the title of the window - RichEdit20A seems to be the name of the control.

The second parameter is a text that is searched in the window. As long as you don't have multiple windows with the same title which only can be distinguished by some text in the window, leave it blank.

Parameter three is the control id. Did you verify using the Window Info tool that 1020 is the control id of the Rich Edit control?

The next problems you will see is flickering of your form - you will have to enter a sleep statement in the loop.

Another problem is that the text in your form accumulates. You have to clear the control before senden the next text.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thank you so much for helping me out water. You're greatly appreciated.

To answer your question "Did you verify using the Window Info tool that 1020 is the control id of the Rich Edit control?"

The answer is yes.

I was trying to use [CLASS:RichEdit20A] in the title position because I thought it would watch that control only since the titlebar changes.

Your suggestion above does exactly as you say. It did start to read the text and display it in my window! It also flickered like you said, and accumulate. So I started trying to see if I can stop those things from happening. I read the help file on the sleep topic and found that Sleep(1000) would make it update once a second. So I added that in, and the flicker stopped! Next I moved onto trying to make it clear the list by using GUICtrlSetData($List1, "") which is not fully working yet. I haven't figured out how to make it "read, display, clear, read again" yet.

I also have some strange results, as all the text from the chat window appears on one line, so it is displaying all of the text from the window in a new line everytime it sees new text. So if the chat looks like:

name:text

othername:moretext

My form shows:

name:textothername:moretext

The various versions of above changes have also made the "X" button on my form stop functioning. I assume this is related to the code to close the form is in the same "While 1" as the rest of my code. So I moved the close functions around. I tried making a "While 2" and putting them in there, as well as a few other things I saw from the examples in the help file and what I searched for here in the forums. I have yet to get that part fixed.

I am still very excited to at least be seeing something show up in my form!

So, what I need to work on:

1:Learn the proper placement of the different pieces of code. (I think this will be the most effective at getting my desired results!)

2:Make it work regardless of what the window title is (as yahelite changes the titlebar based on your screen name, room you're in, and the room topic. ( I have yet to search on this, so it may be very easy)

3:Make the form display text in a correct multiline format.

4:Make the form close when I click the X.

The above results are from about 4 hours of work (mostly reading the forum/man and shifting code around, then running) but I am saturated for the moment.

I just don't want you or anyone else to think I made the change you suggested and immediately posted back here waiting for my next handout. I will work on these new developments until I cannot stand it anymore (at least a few days) then come back begging again :blink:

My code is as of now:

#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <RichEditConstants.au3>

$Form1 = GUICreate("Form1", 639, 233)
$List1 = GUICtrlCreateList("", 8, 8, 621, 214)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    $var = ControlGetText("1221201242069  |  Flirting:1  |  Come in and flirt your heart out", "", 1020)
    GUICtrlSetData($List1, $var)
    Sleep(1000)
    GUICtrlSetData($List1, "")
WEnd
Link to comment
Share on other sites

I modified your script to make it work with Notepad. As I'm running a german Windows you have to change the Notepad title.

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>

Global $sOldText, $sNewText
Global $sNotepadTitle = "Unbenannt - Editor" ; Title of the Notepad Window
$Form1 = GUICreate("Form1", 339, 233)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 321, 214, BitOR($ES_READONLY, $GUI_SS_DEFAULT_EDIT)) ; Create an Edit control and set it to readonly
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    $sNewText = ControlGetText($sNotepadTitle, "", 15)  ; Get the Text from the other application
    If $sNewText <> $sOldText Then                      ; If the text has chanded display it. This way we avoid flickering
        GUICtrlSetData($Edit1, $sNewText)
        $sOldText = $sNewText
    EndIf
WEnd

Ad 2: At least a substring has to stay the same. Then you can use "Opt("WinTitleMatchMode", 2)" to search for this substring anywhere in the title

Ad 3: Solved by my last example

Ad 4: Solved by my last example as I removed the Sleep statement.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

@TitanRain - You're going to have trouble validating that a user's post in chat is actually a post. Since Carriage Returns (CR) and LineFeeds (LF) are perfectly legitimate to send in Yahoo, YahELite lets them create a new line.

eg: if the user `JohnBoy` sends "hi<CR><LF>you: hi there", YahElite will display the text

JohnBoy: hi
you: hi there

(color and styling will still indicate the correct sender though, assuming the sender doesn't guess your local color/styling settings)

Now, if you retrieve the actual RTF being displayed, you might be able to validate that the username is a username, but I'm not sure how/if this can even be done reliably.

One sure way to intercept any incoming post being made is to create a local proxy server between the client/server and read the YMSG packets, but handling the connection and reading packets may be more in-depth than you want. (you could also do changes directly to the incoming packets to make them display differently in the client)

Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

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