Microsoft KB Archive/32432

Using CRT STATUS Clause to Detect Function Keys in COBOL 3.00

PSS ID Number: Q32432 Article last modified on 11-16-1992

3.00 3.00a 4.00 4.50 | 3.00 3.00a 4.00 4.50 MS-DOS | OS/2

Summary: To determine which key has been pressed in an application that uses function keys, include a CRT STATUS clause in the SPECIAL-NAMES section of your program, as in the following example: SPECIAL-NAMES. CRT STATUS IS Key-Status. In the CRT STATUS clause, Key-Status is a 3-byte data item that should be defined in the WORKING-STORAGE SECTION of your program with the following definition: 01 Key-Status. 03 Key-Type PIC X. 03 Key-Code-1 PIC 9(2) COMP-X. 03 Key-Code-2 PIC 9(2) COMP-X.

More Information: Valid values for each part of Key-Status are as follows: 1. Key-Type 0 = Terminator key or auto-skip out of the final field 1 = User-defined function key 2 = COBOL system-defined function key 9 = Error 2. Key-Code-1

PC Keystrokes             User-Function Key Numbers -             -  ESC                         0 F1                         1 F2                         2 F3                         3 F4                         4 F5                         5 F6                         6 F7                         7 F8                         8 F9                         9 F10                       10 SHIFT+F1 (through F10)    11-20 CTRL+F1 (through F10)     21-30 ALT+F1 (through F10)      31-40 ALT+1 (through 9)         41-49 ALT+0 (ALT plus zero)     50 ALT+- (ALT plus hyphen)   51 ALT+= (ALT plus equals)   52 PGUP                      53 PGDN                      54 CTRL+PGUP                 55 CTRL+PGDN                 56 ALT+A (through Z)         65-90 F11                       91 F12                       92 SHIFT+F11                 93 SHIFT+F12                 94 CTRL+F11                  95 CTRL+F12                  96 ALT+F11                   97 ALT+F12                   98 Note: The keys listed above return 0 or 1 in the Key-Type field. 3. Key-Code-2 Undefined - (not currently used) For more information, see Pages 15-6 through 15-8 in the “Microsoft COBOL Compiler 3.0: Language Reference Manual.”

Code Example
***************************************************************** *                      CRTSTAT.CBL                              * *   This program demonstrates how to use the CRT STATUS bytes  * *   to detect if a function key has terminated an accept. * *****************************************************************   SPECIAL-NAMES. CONSOLE IS CRT ***************************************************************** *    CRT STATUS has to be defined in the special-names clause. * *****************************************************************        CRT STATUS IS CRT-STATUS. WORKING-STORAGE SECTION. 01 WS-REPLY              PIC X.   01 WS-DISPLAY-SECOND-BYTE PIC Z9. 01 WS-END-DEMO-FLAG      PIC XXX. 88 END-DEMO VALUE &quot;YES&quot;. ***************************************************************** *    CRT STATUS declaration. * *****************************************************************   01 CRT-STATUS. 05 FIRST-BYTE  PIC X.      05 SECOND-BYTE  PIC 99 COMP-X. 05 THIRD-BYTE  PIC 99 COMP-X. PROCEDURE DIVISION. A-START SECTION. DISPLAY SPACES UPON CRT. DISPLAY &quot;Enter a &quot;&quot;s&quot;&quot; followed by carriage return to termina -   &quot;te the program&quot; at 0310. DISPLAY &quot;Pressing a function key will show you which key was -   &quot;pressed&quot; at 0410. MOVE &quot;NO&quot; TO WS-END-DEMO-FLAG. PERFORM B-ACCEPT UNTIL END-DEMO. STOP RUN. B-ACCEPT SECTION. DISPLAY &quot;Character = &quot; AT 1525. ACCEPT WS-REPLY AT 1537. ***************************************************************** *    This section checks to see if the CRT-status is telling    * *   us that a function key has been pressed. * *    It tells us by setting the first byte in the status bytes  * *   to 1. We can then decode the other bytes to find out      * *   which function key has been pressed. The value returned   * *   corresponds to the value defined by config. * *    If the first byte returns with a value of 0, then the      * *   return key terminated the accept. * *****************************************************************   IF FIRST-BYTE = &quot;0&quot; THEN IF WS-REPLY = &quot;s&quot; OR WS-REPLY = &quot;S&quot; MOVE &quot;YES&quot; TO WS-END-DEMO-FLAG GO TO B-END. IF FIRST-BYTE = &quot;1&quot; THEN DISPLAY &quot;You hit function key&quot; AT 1725 MOVE SECOND-BYTE TO WS-DISPLAY-SECOND-BYTE DISPLAY WS-DISPLAY-SECOND-BYTE AT 1746. B-END. EXIT. Copyright Microsoft Corporation 1992.