wintin Forum Index wintin
Wintin Discussion Forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Screen text capture

 
Post new topic   Reply to topic    wintin Forum Index -> Addins
View previous topic :: View next topic  
Author Message
Normstorm
Veteran


Joined: 29 Jun 2005
Posts: 28

PostPosted: Mon Jul 04, 2005 9:53 am    Post subject: Screen text capture Reply with quote

Which Service, class, or method do I use for example to retrieve the last 50 or 100 lines of text that are currently displayed on the screen?
Back to top
View user's profile Send private message Visit poster's website AIM Address
william
Site Admin


Joined: 07 Dec 2003
Posts: 539

PostPosted: Tue Jul 05, 2005 7:28 pm    Post subject: Reply with quote

The Workbench service exposes masterPuttyControl, which is the Putty (terminal) control object representing the main window. You can call that object's GetScrollbackLine method to get a line from the scrollback: workbench.masterPuttyControl.GetScrollbackLine(-1) gets you the most recently displayed line, GetScrollbackLine(-2) the previous one, and so on until eventually it will give you nulls when there are no more lines.

If you want to look in a different window, you can use the workbenches FindPadPanel or FindWindowPanel methods to get the window control you want, and coerce it to a PuttyControl - but make sure it's the right type first, in case someone's created a different type of window with the name you're looking for.

Have a look at the implementation of the find command in workbench.cs for an example.
Back to top
View user's profile Send private message Send e-mail
Normstorm
Veteran


Joined: 29 Jun 2005
Posts: 28

PostPosted: Wed Jul 06, 2005 12:47 am    Post subject: Reply with quote

Thanks William, this was exactly what I was looking for.

For the benefit of other developers, for future reference (no pun intended), you need to add the IPuttinWin and PuttyControl reference to your project because GetScrollbackLine() is a member of PuttyControl.
Back to top
View user's profile Send private message Visit poster's website AIM Address
Normstorm
Veteran


Joined: 29 Jun 2005
Posts: 28

PostPosted: Wed Jul 06, 2005 4:03 am    Post subject: Reply with quote

Ok, I might've spoken too hastily. This method almost works, except the GetScrollbackLine method seems to return the very first line that you cannot see on screen, ie. it returns lines which begin outside of what the user can view. So GetScrollbackLine would be the first line if you were to hit the up button the scroll bar. However if I go over 0 to positive integers, I run into where it is null as you had mentioned. What I really am looking to capture in addition to the text which has already scrolled off screen but the text currently on screen as well. Below is some code which illustrates the issue.

Code:

string tmpString = null;
StringBuilder sb = new StringBuilder;
int negCounter = -1;
int numLines = 10;

for (int i = 0; i < numLines; i++)
{
   if (workBench.masterPuttyControl.GetScrollbackLine(negCounter) != null)
   {
     tmpString = workBench.masterPuttyControl.GetScrollbackLine(negCounter--);
     sb.Insert(0, "\n" + tmpString);
   }
   else
   {
      break;
   }
}


I've looked around some, and at the time of writing this post I can't seem to find any method. Perhaps I'm using the method incorrectly?
Back to top
View user's profile Send private message Visit poster's website AIM Address
Gimic
Juggernaut


Joined: 16 Jun 2005
Posts: 62

PostPosted: Wed Jul 06, 2005 2:50 pm    Post subject: Reply with quote

Normstorm wrote:
Ok, I might've spoken too hastily. This method almost works, except the GetScrollbackLine method seems to return the very first line that you cannot see on screen, ie. it returns lines which begin outside of what the user can view. So GetScrollbackLine would be the first line if you were to hit the up button the scroll bar. However if I go over 0 to positive integers, I run into where it is null as you had mentioned. What I really am looking to capture in addition to the text which has already scrolled off screen but the text currently on screen as well. Below is some code which illustrates the issue.

Code:

string tmpString = null;
StringBuilder sb = new StringBuilder;
int negCounter = -1;
int numLines = 10;

for (int i = 0; i < numLines; i++)
{
   if (workBench.masterPuttyControl.GetScrollbackLine(negCounter) != null)
   {
     tmpString = workBench.masterPuttyControl.GetScrollbackLine(negCounter--);
     sb.Insert(0, "\n" + tmpString);
   }
   else
   {
      break;
   }
}


I've looked around some, and at the time of writing this post I can't seem to find any method. Perhaps I'm using the method incorrectly?



Are you wanting to capture text as it comes in? Say like begin a capture, to print to a file? Or do you actually want to be able to just pull everything that has allready been received, and put it to a file or whatever?
Back to top
View user's profile Send private message
Normstorm
Veteran


Joined: 29 Jun 2005
Posts: 28

PostPosted: Wed Jul 06, 2005 5:31 pm    Post subject: Reply with quote

Gimic wrote:

Are you wanting to capture text as it comes in? Say like begin a capture, to print to a file? Or do you actually want to be able to just pull everything that has allready been received, and put it to a file or whatever?


I want to do the latter, just pull what has already been received and displayed on screen. I had alluded to the architecture in another thread, I believe the #delgroup discussion.




But basically say I define an alias...like

gs

short for grabscreen..

And say my character's name is John, a mage.

If I'm the node labelled John on the far left in the illustration and perform a

gs Bob 17

It sends to my server a XML message, GRABSCREEN. http://www.normstorm.com/omc/grabscreen.xml

The server forwards that XML message on to Bob. Bob does a screen capture of his last 17 lines and sends it back to the server which routes it back to John. The return message including the screen capture is SCREENGRAB. http://www.normstorm.com/omc/screengrab.xml
Then this XML message is checked for well-formedness, and eventually text from Bob's screen is displayed in John's Wintin.NET screen. This is just one of the features of the AddIn I'm working on.

Now I have this all implemented and working, except what I'm capturing using the GetScrollBackLine() method is actually 17 lines from the last line that has scrolled past, and not 17 lines from the last line displayed currently on screen.

So I'd like to get what's really on Bob's screen, not the last 17 lines which have scrolled off screen.

Thoughts?


Last edited by Normstorm on Thu Jul 07, 2005 8:36 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website AIM Address
william
Site Admin


Joined: 07 Dec 2003
Posts: 539

PostPosted: Thu Jul 07, 2005 8:29 pm    Post subject: Reply with quote

hmm. Looks to me as though there is a bug in the underlying method - I hadn't thought of it, but it should give you the screen content with positive integers. I've raised a bug for this.

Just to check - this will give you what's on the screen - so any gags, subs and so on will be applied. You sure you want that? If you want the raw incoming text you're better off writing an incoming text event handler to capture it.
Back to top
View user's profile Send private message Send e-mail
Normstorm
Veteran


Joined: 29 Jun 2005
Posts: 28

PostPosted: Thu Jul 07, 2005 8:45 pm    Post subject: Reply with quote

william wrote:
Just to check - this will give you what's on the screen - so any gags, subs and so on will be applied. You sure you want that? If you want the raw incoming text you're better off writing an incoming text event handler to capture it.


Yup, I want what's exactly on the user's screen, including any processing that was applied to the text.

But if I were to explore the incoming text event handler route, what class should I pull from ServiceManager and what method should I look into?
Back to top
View user's profile Send private message Visit poster's website AIM Address
william
Site Admin


Joined: 07 Dec 2003
Posts: 539

PostPosted: Thu Jul 07, 2005 8:57 pm    Post subject: Reply with quote

You would look at the ReceivedText event handler:

ReceivedText rt = (ReceivedText) ServiceManager.Services.GetService(typeof(ReceivedText));
rt.ReceivedLine += new ReceivedTextEventHandler(OnReceivedLine);
Back to top
View user's profile Send private message Send e-mail
Normstorm
Veteran


Joined: 29 Jun 2005
Posts: 28

PostPosted: Sun Jul 10, 2005 5:45 am    Post subject: ANSI escape sequence stripper Reply with quote

Kinda ironic, I went about the whole route of adding a ReceivedLine event handler and now 1.05 comes out! But I think it's cool that I got to learn this method and might just stick with.

One thing that might be of use to some developers is that the text coming from this you gotta get it via e.Text.EncodedText.ToString() assuming e is ReceivedTextEventArgs.

Another thing which is interesting is that it still has the ANSI color coding with escape sequences which is nice to have. But since I didn't need it and wanted just the plain text without color markup, I wrote the following which strips out ANSI escape sequences which may be handy for some people so they don't have to write it from scratch.

Code:

      public static byte[] ConvertStringToByteArray(string stringToConvert)
      {
         return (new UnicodeEncoding()).GetBytes(stringToConvert);
      }


      public string filter(string s)
      {
         
         byte[] bytes = ConvertStringToByteArray(s);
         StringBuilder buffer = new StringBuilder();
         bool escape = false;

         for (int i = 0; i < bytes.Length; i++)
         {
            if(bytes[i]<=127 && bytes[i]>=32 && !escape)
            {
               buffer.Append((char)bytes[i]);
            }
            if(bytes[i]=='\n')
            {
               buffer.Append((char)bytes[i]);
            }

            if(bytes[i]<32)//debug               
            {
               //System.out.println(bytes[i]+"="+(char)bytes[i]);
            }
            if(bytes[i]==27)
            {
               escape = true;
            }
            if(bytes[i]=='m' && escape)
            {
               escape = false;
            }
         }
         return buffer.ToString();
      } 


Thanks william for your help.
Back to top
View user's profile Send private message Visit poster's website AIM Address
william
Site Admin


Joined: 07 Dec 2003
Posts: 539

PostPosted: Sun Jul 10, 2005 10:15 am    Post subject: Reply with quote

The EncodedString class is wintin's handler for ANSI encoded text.

If you want to strip ANSI sequences, use e.Text.ClearText instead of e.Text.EncodedText. EncodedString has some methods which might be helpful: find text of a particular colour, substitute one string for another while preserving colour sequences, that kind of thing.

regards

William
Back to top
View user's profile Send private message Send e-mail
Normstorm
Veteran


Joined: 29 Jun 2005
Posts: 28

PostPosted: Sun Jul 10, 2005 1:48 pm    Post subject: Reply with quote

Ok that helps a ton. I feel silly for re-inventing the wheel. I guess when I first looking, I might've thought that ClearText was a method instead of a property. Thanks again.
Back to top
View user's profile Send private message Visit poster's website AIM Address
Gimic
Juggernaut


Joined: 16 Jun 2005
Posts: 62

PostPosted: Wed Aug 03, 2005 8:37 pm    Post subject: Reply with quote

Nord, have you had a performance issue when implementing the received text event handler?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    wintin Forum Index -> Addins All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group