ASNA Mobile RPG® Reference Manual

5250 Terminal Keyboard Macros

The ASNA 5250 Terminal Emulator code provides a function that accepts an array of Actions and/or characters, and executes each in the sequence specified by the array positions.

The function is called:

WingsTerminal.executeMacro(macro);

where, macro is an instance of an array of strings, with elements containing names of Actions or, if the length of the string is one, the string is used as a character to be processed by the emulator as if it were entered directly from the keyboard. There is no need to indicate Shift, Control, or Alt on keystrokes, since the Actions produced by such combinations can be requested directly. (The Wings prefix is derived from ASNA Wings, another member of the Monarch Family that uses a similar terminal emulator.)

The first string in the array is reserved for the name of the macro.

For example, let's assume that we want a macro to execute the following steps.

  1. Move the cursor to the first field and position one (Record Home).
  2. Enter 'ADDLIBLE CAROLINA' (Add Library List Entry CAROLINA).
  3. Submit page with 'Enter' Aidkey.

Let's add a Button control to the ~/Themes/Current/Asna5250Terminal.aspx markup, using the Function Key area in the default MasterPage. The following Button control may be added before the "CenPH" asp:Content section.

 <asp:Content ID="FileContent1" runat="server" ContentPlaceHolderID="FKeyPH">
   <button onclick= "return testMacro();">Add Libl Entry Macro</button>
</asp:Content> 

The implementation of the testMacro()> JavaScript function is as follows.

testMacro = function () 
{
   var macro = [
      'Test Macro', // The name of the Macro (ignored during execution)
      'RECORD',     // First action, goto Home position
      'A', 'D', 'D', 'L', 'I', 'B', 'L', 'E', ' ',
      'N', 'U', 'T', 'S', 'N', 'B', 'O', 'L', 'T', 'S',
      'ENTER' 
    ];

   WingsTerminal.executeMacro(macro);

   return false;
}

Notice how the array contains two Actions: 'RECORD' and 'ENTER', which are both case sensitive. These are two of the actions listed in Keyboard Mapping. 'RECORD' moves the cursor to the Home position and 'ENTER' submits the page with an QSN_ENTER (0xf1) Aid key. The rest are letters that are typed to fill the input field (ADDLIBLE and NUTSNBOLTS). Once the macro array has been declared, all we need to do is call the WingsTerminal.executeMacro function with the macro as the only parameter. Lastly, returning false to the onclick event prevents it from executing any further actions.

Macros are Interrupted after Submitting a Page

The macro is interrupted when it executes any Action that causes the Page to be submitted because of the Stateless behavior of Web applications. In fact, the JavaScript that implements the ASNA 5250 Terminal Emulator, as well as any JavaScript in the page, is released from memory and re-loaded when the request is returned.

There are advanced techniques that can be implemented to split a large macro into segments, divided by submitting Actions and those that are to be continued the next time the page renders again, which could also contain submitting Actions.

These techniques involve storing the macro in a file (or local storage) as well as the state regarding the segments already executed. A hidden field may be added to the page with the segment of the macro to be executed the next time; and the JavaScript can control the subsequent segments to be executed. ~/Themes/Current/Asna5250Terminal.aspx code behind may be altered to accomplish these steps.

Special Note:

Any references to the directory location of Asna5250Terminal.aspx in the above specifies ~/Themes/Current/ as the location. Refer to Setting the location of the Asna5250Terminal.aspx page for more information.

See Also

5250 Terminal Branding
Keyboard Mapping
Terminal Menus