Handling Events
Events are an integral part of the API, and provide an asynchronous way to handle state changes in Reflection 2008. 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
void screen_BeforeSendKeys(object sender, BeforeSendKeysEventArgs args)
{
int row = args.Row;
int col = args.Column;
if (row == 5 && col == 10)
{
args.Keys = "theUserId";
}
else if (row == 6 && col == 11)
{
args.Keys = "pwd";
}
else if (row == 20 && col == 2)
{
args.Cancel = true;
}
}
IIbmScreen screen = ibmTerminal.Screen;
screen.BeforeSendKeys += new BeforeSendKeysEventHandler(screen_BeforeSendKeys);
Note: If you adopt this example for your own applications, replace the logic with your own logic, but keep the method signature the same per event delegate.
|