Reflection Desktop VBA Guide
HowTos / Log User Input
In This Topic
    Log User Input
    In This Topic

    This sample saves all of the text entered into a session by a user to a log file. Only text entered by the user is saved.

    If you prefer to run macros in pre-configured sessions instead of creating your own sessions, you can download the VBA Sample Sessions and open the log-user-input.rd3x (IBM) and log-user-input.rdox (Open Systems) files. The download package contains everything you need to run the macros in these files. See Download the VBA Sample Sessions.

    This article contains tabbed content that is specific to each terminal type. Be sure the tab for your Which Terminal Type are you Using? is selected.

    To run this sample

    1. In an Ibm terminal session, Open the Visual Basic Editor and then copy the code into the ThisIbmScreen code window.
    2. Save the session and then reopen it.
    3. Enter some data on a terminal session screen and open the log file to check the results. (The .log file has the same name as your session document file and is in the same folder as that file.)
      Log user input
      Copy Code
      Public buffer As String
      
      'Save each key that is entered into a buffer
      Private Function IbmScreen_BeforeSendKeys(ByVal sender As Variant, Keys As String, ByVal row As Long, ByVal column As Long) As Boolean
        
          buffer = buffer & Keys
          IbmScreen_BeforeSendKeys = True
        
      End Function
      
      'Before the screen is changed, append the buffer to a text file.
      Private Function IbmScreen_BeforeSendControlKey(ByVal sender As Variant, key As Long) As Boolean
        
          Set fso = CreateObject("Scripting.FileSystemObject")
          'Open a text file to append data
          Set ts = fso.OpenTextFile(ThisIbmTerminal.SessionFilePath & ".log", 8, True)
          ts.Write buffer & "<Key(" & key & ")>" & vbCrLf
          ts.Close
          'Clear the buffer
          buffer = ""
          IbmScreen_BeforeSendControlKey = True
        
      End Function                         
                       
      

    To run this sample

    1. Open an Open Systems terminal session, open the Visual Basic Editor and then copy the code into the ThisScreen code window.
    2. Save the session and reopen it.
    3. Enter some data on a terminal session screen and open the log file to check the results. (The .log file has the same name as your session document file and is in the same folder as that file.)
    Log user input
    Copy Code
    Dim buffer As String
    
    'Save each key that is entered into a buffer
    Private Function Screen_KeysSending(ByVal sender As Variant, Keys As String) As Boolean
        
        buffer = Buffer & Keys
        Screen_KeysSending = True
    
    End Function
    'Before the screen is changed, append the buffer to a text file.
    Private Function Screen_ControlKeySending(ByVal sender As Variant, Key As Attachmate_Reflection_Objects_Emulation_OpenSystems.ControlKeyCode) As Boolean
       
        Set fso = CreateObject("Scripting.FileSystemObject")
        'Open a text file and append data
        Set ts = fso.OpenTextFile(ThisTerminal.SessionFilePath & ".log", 8, True)
        ts.Write Buffer & "<Key(" & Key & ")>" & vbCrLf
        ts.Close
        'Clear the buffer
        buffer = ""
        Screen_ControlKeySending = True
    
    End Function
    

    Concepts

    These samples use events to capture and save data users enter during a terminal session.

    As the user enters text, the BeforeSendKeys (IBM) or KeysSending (Open Systems) event adds the text entered to a buffer before each key is sent.

    When the control key is pressed,  the BeforeSendControlKey (IBM) or ControlKeysSending (Open Systems) events are handled to append the text in the buffer to a file. The buffer is cleared before the control key is sent. 

     

    See Also