The sending of keystrokes and action commands to the host screen is performed using the HostScreen object. The two methods that perform these functions are:
•putKeys
•putCommand
The putKeys method is used to send keystrokes to the host screen. This results in interaction with the screen. Keystrokes are the standard alphabetical and numerical type of keys.
The putCommand method is used to send actions to the host. This results in interaction with the host. Action commands are those such as the enter key, or the PF3 key.
Keys sent to the host screen will be placed at the current location of the cursor. In order to jump between fields the TAB mnemonic can be used. For example a typical signon screen would require a username and password be entered, followed by the enter key. Refer to the following sample code.
After running the code above, the TraceView tool can be used to view the sequence of events. After making the connection the screen below appears. In the code above, the HostScreen object is instantiated by using the getScreen method. We know that the first screen has the cursor placed in the User Profile field, so the name "simmy" can be sent using the putKeys method. The trace shows in red where the screen has changed after the enter action has been sent using the putCommand.
It is good practice to use a command such as the waitForUpdate to ensure that the screen has changed before issuing the next set of instructions.
As with the previous screen, the location of the cursor is known to be in the correct field, so only the key with the character of "2" needs to be sent to the screen, followed by the enter action.
After performing another waitforUpdate method to ensure that the screen has changed, the signon screen appears. The usage of putKeys is a bit more interesting here, because more than field is being updated using just one command. The keys "simmy[tab]host" have the special mnemonic tab which results in the tab key being used between the userid and password. This causes the cursor to jump from the userid field to the password field.
Once the enter action has been processed, the session is stopped.