How to monitor typing in the terminal and notify users using the statusbar

  • 7023488
  • 31-Oct-2018
  • 31-Oct-2018


Reflection Desktop 16.1 and higher
InfoConnect Desktop 16.1 and higher


While typing in the terminal, people may occasionally need hints to help them with a terminal command they just typed, or they may need to be warned about severe consequences that their recent typing may produce. In Reflection or InfoConnect Visual Basic for Applications (VBA), an "AfterSendKeys" event-handler macro can be used to monitor typing, and a helpful message can be displayed on the status-bar when specific typing is recognized.  The following example explains how to get started with implementing a keystroke-monitor like this, which can be customized to meet the unique needs of your host system.


First, open the Reflection or InfoConnect VBA Editor - look for this on the "Macros" tab, or the "Macro" menu in the session. Select the Screen object module in the Project tree on the left. Note: the name of this will vary depending on what type of host system is being used.

Then on the right side of the editor window, select the Screen object from the left drop-down list, and "AfterSendKeys" from the right drop-down list. Visual Basic will automatically insert a "stub" for the AfterSendKeys event-handler function, as shown. For Unix\OpenVMS terminal types, the Screen event name is "KeysSending".

Add code to the empty event-handler, which will collect individual keys as they are typed, and will look for any special combination that might be interesting...

Private Sub IbmScreen_AfterSendKeys(ByVal sender As Variant, ByVal Keys As String, ByVal row As Long, ByVal column As Long)
    Static collected As String
    collected = collected & Keys
    If LCase(Right(collected, 5)) = "xyzzy" Then
        ThisFrame.StatusBarText = "Nothing happens."
        ThisFrame.StatusBarText = ""
    End If
End Sub

Additional conditions to check for various typed words or phases can be added following a similar pattern.


Additional Information

An alternative approach to this type of monitoring would be to use the "BeforeSendControlKey" event. This event occurs after someone presses Enter, PF1, Clear, and so on, and allows the VBA programmer to prevent the control-key from actually being sent to the session, if, for example, some undesirable typing is on the screen. Data entry can be checked for correctness this way before it reaches the host system.