Walkthroughs > Log User Input and Credit Card Access > Save Screens As Text Or Images |
You can monitor and log the screens accessed by users during a session. This walkthrough shows how to save the screens as text and images.
Check for terminal type and create event handler |
Copy Code
|
---|---|
using System; using System.Collections.Generic; using System.Text; using Attachmate.Reflection.UserInterface; using Attachmate.Reflection.Framework; using Attachmate.Reflection.Emulation.IbmHosts; using System.IO; namespace SaveScreens { class Program { static void Main(string[] args) { //Get the last activated instance of InfoConnect Application app = MyReflection.ActiveApplication; //Make sure InfoConnect is running if (app != null) { IFrame frame = (IFrame)app.GetObject("Frame"); IView view = (IView)frame.SelectedView; //If this is an IBM terminal, save the screens if (view.Control.ToString() == "Attachmate.Reflection.Emulation.IbmHosts.IbmTerminal") { IIbmTerminal terminal = (IIbmTerminal)view.Control; IIbmScreen screen = terminal.Screen; //Handle the BeforeSendControlKey event to save screens screen.BeforeSendControlKey += new BeforeSendControlKeyEventHandler(screen_BeforeSendControlKey); } } else { Console.WriteLine("Cannot find instance of InfoConnect"); } Console.ReadKey(); } } } |
![]() |
Alternatively, you could save screen images by turning on ScreenHistory and then saving all images before the session is closed. |
Save screens as text or images |
Copy Code
|
---|---|
//screenNumber is a counter used to provide a unique name for each screen image file static public int screenNumber = 0; //Handle BeforeSendControlKey to save the screen before the Transmit key is sent static void screen_BeforeSendControlKey(object sender, BeforeSendControlKeyEventArgs args) { IIbmScreen screen = (IIbmScreen)sender; byte[] screenImage; //Write output only if the control key is Transmit. (Don't write output if tabs or other //control keys are pressed.) if (args.Key.Equals(ControlKeyCode.Transmit) == true) { screenNumber++; //Get all the text on the screen and append it to a file along with a divider to indicate the end of the screen string text = screen.GetTextEx(1, 1, screen.Rows, screen.Columns, GetTextArea.Block, GetTextWrap.Off, GetTextAttr.Any, GetTextFlags.CRLF); string fileName = @"C:\users\" + Environment.UserName + @"\Documents\userInputLog.txt"; StreamWriter w = File.AppendText(fileName); w.WriteLine(text); w.WriteLine("..................................................................."); w.Close(); //Save screens as images. screenImage = screen.Parent.Productivity.ScreenHistory.GetLiveScreenImage(); string imageFileName = @"C:\users\" + Environment.UserName + @"\Documents\Screen" + screenNumber.ToString() + @".png"; File.WriteAllBytes(imageFileName, screenImage); } } |