Reflection 2014 .NET API Guide
Handling Events

Handling Events

Events are an integral part of the API, and provide an asynchronous way to handle state changes in Reflection. By implementing event handler methods, you can receive notifications for all event-generating activity, such as keyboard input and host actions. In many cases, you can modify or cancel the activity that caused the event.

For example, BeforeSendKeys is an event that notifies you after a series of keys is entered — either programmatically or by a user — but before it is sent to a host. To prevent specific keys from being sent to a host, you can set the Cancel property to "true" in the event argument or modify the key values in the event argument.

The following code sample illustrates this concept:

BeforeSendKeys Example

//This sample uses the BeforeSendKeys event from an IbmScreen object.
  void screen_BeforeSendKeys(object sender, BeforeSendKeysEventArgs args)
    {
        int row = args.Row;
        int col = args.Column;

        if (row == 5 && col == 10)
        {

      //For the purpose of example only, we assume that position (5,10) is the user id field and we always use this user id ("theUserId"). Generally speaking, hard-     coding ids or passwords isn't recommended.
          args.Keys = "theUserId";
        }
        else if (row == 6 && col == 11)
        {

      //For the purpose of example only, we assume that position (6,11) is the user password field and we always use this password ("pwd").
          args.Keys = "pwd";
        }
        else if (row == 20 && col == 2)
        {

      //For the purpose of example only, we assume that position (20,2) is an input field from which to select a menu command. This effectively disables the command on the host application without rewriting the host application.
          args.Cancel = true;
        }

      // Let all other keystrokes pass, as usual.

  }


//Attach the event handler to the IbmScreen object's BeforeSendKeys event, where ibmTerminal is an instance of IbmTerminal.

IIbmScreen screen = ibmTerminal.Screen;
screen.BeforeSendKeys += new BeforeSendKeysEventHandler(screen_BeforeSendKeys);