The mapping of keys to functions is one of the main activities of the Terminal Manager. If you understand what happens when a user presses a key, you'll have a good feel for how you can control the interaction between the keyboard and the COBOL application. The next diagram depicts the overall process, from keystroke to COBOL program:
ACTION EXAMPLE
The following text describes in detail the steps shown above.
4.3.1.1 Key interpretation
When the user presses a key, the keyboard sends a signal to the computer. This signal needs to be interpreted and translated into a value, or functionality, that the COBOL program can understand. This process begins with the terminal database file.
The terminal database file equates hardware signals to logical values. Unless you are running on a system such as MS-DOS, where the key interpretation is built into the runtime, your terminal needs to be listed in the terminal database file. Keystrokes at the terminal generate hardware signals, and each hardware signal must be equated to a logical value if the application program is to respond to the associated keystroke. These logical values, called key codes, are listed in the "Table of Keys" at section 4.3.2.3.
Acucorp provides the definitions for many popular terminals in the terminal database file that we send you. If the name of your terminal is included, you will not need to change anything unless your particular terminal is different from the standard configuration for its type. If that is the case, you may need to change the entry.
Each entry in the terminal database file consists of the name of the terminal (including all names by which you might typically refer to this terminal type), followed by a series of character strings. Some of these strings are equations that assign hardware signals from the keyboard to key codes that we provide. Some of the strings consist of functional instructions to the terminal.
Section 4.6 completely describes terminal database file entries and the syntax rules for them.
4.3.1.2 Key translation
After the hardware signal has been equated to a key code, the runtime system checks the runtime configuration file to determine if any special values or functions have been attached to the key code.
This is the point at which statements in a COBOL program can override what is specified in the runtime configuration file.
4.3.1.3 Keyboard configuration
Each terminal has several keys that are available to be used for special purposes. Some of these keys are used as field termination keys, others are used as editing keys. ACUCOBOL-GT supports a large number of special keys, but in the default configuration, only these are used:
Function Keys 1-20 Help Arrow Keys Do Page Up Page Down Backspace Line-Kill Home End Insert Delete Clear Clear to End Carriage Return Control Keys
The Backspace and Line-Kill keys are whichever keys provide these functions for your operating system. The Backspace key is the one that erases individual characters from a command line; the Line-Kill key is the one that can cancel a command line. On most systems, the key that performs the Backspace function is the one labeled either "backspace" or "delete."
The keyboard interface can be easily configured to meet a variety of needs. The default configuration has the following characteristics:
1. The range of legal input characters is ASCII values 32 through 255. Other characters outside this range are ignored unless covered by one of the cases below.
2. The range of exception characters is ASCII values 1 through 31. If any of these characters is typed, an exception condition exists and input to the field is terminated. The exception key value is identical to the ASCII value of the key. For example, if Control-E is typed, then the exception key value returned would be "5". This rule does not apply to characters specifically listed in rule 3.
3. The following table outlines the actions of other keys. In this table, Action is the special action performed by the key. If a number is present here, then this key terminates the field and returns that number as its termination key value. If the number is starred (*), then this key also causes an exception condition. If there are both a number and an action, then the key acts as a termination key when the action cannot be applied.
The Windows/MS-DOS column names the keycap on the IBM-PC keyboard that is used for this key. The Termcap column names the terminal database file entry that corresponds to this key for UNIX and VMS systems.
Key Action Windows/MS-DOS Termcap Carriage Return 13 Enter
Tab Next Field (9) Tab
Host's Backspace Backspace BkSp
Host's Line-Kill Erase Field
Backtab Previous Field Shft-Tab kB
Home First Field Home kh
End Last Field End KE
Insert Auto-Insert Mode Ins KI
Delete Delete Character Del KX
Clear Erase Field Ctl-Home KC
Clear-to-End Erase Remainder Ctl-End kE
Left Arrow Left Left kl
Right Arrow Right Right kr
Up Arrow Previous-All (52*) Up ku
Down Arrow Next-All (53*) Down kd
Page Up Page-Up (67*) PgUp kP
Page Down Page-Down (68*) PgDn kN
Do (Command) 40* Alt-D KD
Help 90* Alt-H K?
F1 - F10 1 - 10* F1 - F10 k1 - k0
F11 - F20 11 - 20* Shft F1 - F10 K1 - K0
When accepting data from the keyboard, the Terminal Manager runs in one of two modes: "standard" mode or "auto" mode. In "standard" mode, the only way to finish input is by typing one of the allowed termination keys; the cursor may not leave the field. In "auto" mode, the cursor can leave the field; when the user fills the field with data, it is immediately accepted and the cursor moves on. The setting of "auto" mode or "standard" mode is determined by the various clauses specified on the ACCEPT statement. For details, see Chapter 6 of the Reference Manual, ACCEPT verb.
There are four different methods for accepting a field (ACCEPT verb, Format 1), depending on the mode and the presence of either the CONTROL KEY clause or the ON EXCEPTION clause. These are:
Standard mode, no CONTROL KEY or ON EXCEPTION clause: the field can be accepted only by a termination key. In the default keyboard configuration, these are the Carriage Return and Tab keys.
Standard mode, with CONTROL KEY or ON EXCEPTION clause: the field can be accepted by a termination key or by one of the exception keys.
Auto mode, no CONTROL KEY or ON EXCEPTION clause: the field can be accepted by a termination key or by filling the field with data.
Auto mode, CONTROL KEY or ON EXCEPTION clause: the field can be accepted by filling it with data, or by a termination key or an exception key.
The Terminal Manager can control more than one field when the program is doing an ACCEPT that refers to a Screen Section item (ACCEPT verb, Format 2). In the course of this ACCEPT, the user can move between the fields by using the Tab, Backtab, Left, Right, Up, Down, Home and End keys; the Tab key acts as a terminate key only in the last field. A Format 2 ACCEPT statement does not support the use of the CONTROL KEY clause; the CRT STATUS phrase of the Special-Names paragraph may be substituted. Data entry for a Screen otherwise falls into four categories much like the above.
The termination and exception keys may be changed by runtime configuration options as described in section 4.3.2, "Redefining the Keyboard."
1. Under MS-DOS, RM/COBOL-85 defines the Command key to be Alt-C. When you are typing this key it is easy to accidentally type Control-C instead, which is the interrupt key in DOS. For this reason, ACUCOBOL-GT uses Alt-D (for "Do") instead.
2. ACUCOBOL-GT defines more editing keys than RM/COBOL-85 does. In particular, the Home, End, Clear, Clear-to-End and Line-Kill keys return exception values under RM/COBOL-85, while under ACUCOBOL-GT they perform various field-editing functions.
3. ACUCOBOL-GT defines Page Up, Page Down, and Help keys that are not defined under RM/COBOL-85. These keys are used by the ACUCOBOL-GT debugger.
4. The default RM/COBOL-85 keyboard includes the following keys as exception keys: Attention, Home, New Line, Tab Left, Erase Right, Tab Right, Insert Line, Delete Line, and Send. Under ACUCOBOL-GT, these keys either act as editing keys or are ignored. Because these keys are generally not available on most keyboards (or, in the case of the Tab Right and New Line keys, are ambiguous with control keys), most applications do not use them. If you need to use any of these keys, you can alter the ACUCOBOL-GT keyboard configuration as described in section 4.3.2, "Redefining the Keyboard."
5. The RM/COBOL-85 default keyboard layout varies from machine to machine. In the interest of portability, the default ACUCOBOL-GT keyboard interface is the same for all machines.