This example displays up to 10 terminal keys stored in the terminal key buffer. In this example, only the up, down, right, left, and return keys are identified. To create a function that can identify all terminal keys refer to online help for either 3270 terminal keys or 5250 terminal keys.

To create a terminal key buffer, first run this set the buffer size:

Sub CreateBuffer

 Session.SetTermKeyBuffer 10, rcOverflowShift

End Sub

Next, move the cursor in the terminal window using the arrow keys. Reflection stores your keystrokes in the terminal key buffer. Run DisplayKeyName to display the keys you pressed. DisplayKeyName calls the user-defined TermKeyName function shown here, which converts terminal key codes to descriptive strings. (This example returns names for only 5 sample keys. Other keys return "Unidentified key".) When the DisplayKeyName procedure has completed, the terminal key buffer will be empty.

'This function converts terminal key codes to descriptive strings.


Function TermKeyName(keyCode as long) As String

 Select Case keyCode

  Case rcIBMDownKey

   TermKeyName = "Down Key"

  Case rcIBMUpKey

   TermKeyName = "Up Key"

  Case rcIBMLeftKey

   TermKeyName = "Left Key"

  Case rcIBMRightKey

   TermKeyName = "Right Key"

  Case rcIBMEnterKey

   TermKeyName = "Enter Key"


  'For this sample all other keys are unidentified

  Case Else

   TermKeyName = "Unidentified key"

 End Select

End Function


Sub DisplayKeyName ()

With Session

 Dim key As Long


  'Get the next key value from the buffer

  key = .GetBufferedTermKey


  'Exit the loop if the buffer is empty

  If key = 0 then exit do


  'Display the key name returned by the TermKeyName function

  MsgBox TermKeyName(key)


End With

End Sub