Microsoft KB Archive/45890
How to Trap Arrow Keys in COBOL 3.0 Using KEYBCF
PSS ID Number: Q45890 Article last modified on 04-20-1993
3.00 3.00a | 3.00 3.00a MS-DOS | OS/2
|The information in this article applies to:|
|- Microsoft COBOL for MS-DOS and OS/2, versions 3.0 and 3.0a|
Summary: This article describes how to trap the arrow keys in COBOL Version 3.0 or 3.0a using the KEYBCF utility. This is a two-step process that uses the KEYBCF keyboard configuration utility to remap the cursor keys as function keys and uses the SPECIAL NAMES entry CRT STATUS in the COBOL program.
More Information: Before running the program below, you must first define the function keys using KEYBCF. The steps for setting up the arrow keys as user function keys 14 through 17 are as follows: 1. Run KEYBCF. 2. Press 2 for “Alter function key definitions.” 3. Press 3 for “Alter user function keys.” 4. Press the SPACEBAR 14 times to move to function key 14. 5. Press the RIGHT ARROW key and pause for the key to be accepted. 6. Press the UP ARROW key and pause for the key to be accepted. 7. Press the LEFT ARROW key and pause for the key to be accepted. 8. Press the DOWN ARROW key and pause for the key to be accepted. 9. Press Q for “Quit.” 10. Press 5 for “Exit to main menu.” 11. Press 3 for “Save function key definitions.” 12. Press 4 for “Exit.” This method of trapping keys can be used for any key, but there are easier methods for most other keys.
Code Example: The sample below accepts any terminator key and displays the CRT STATUS values of the key. If the terminator was an arrow key and the above steps were taken with KEYBCF, the program displays the direction of the arrow key. The code example is as follows: $SET ANS85 SPECIAL-NAMES. CRT STATUS IS CRT-STAT. DATA DIVISION. WORKING-STORAGE SECTION. 01 CRT-STAT. 03 KEY-TYPE PIC X. 03 KEY-CODE-1 PIC 99 COMP. 03 KEY-CODE-2 PIC 99 COMP. 77 JUNK PIC XX. SCREEN SECTION. 01 JUNK-SCREEN. 05 BLANK SCREEN. 05 LINE 2 COLUMN 1 VALUE “Press arrow key”. 05 LINE 3 COLUMN 5 PIC XX TO JUNK. PROCEDURE DIVISION. MAIN. DISPLAY JUNK-SCREEN. ACCEPT JUNK-SCREEN. DISPLAY “CRT-STATUS VALUES”. DISPLAY “KEY-TYPE =” KEY-TYPE. DISPLAY “KEY-CODE =” KEY-CODE-1. EVALUATE KEY-TYPE ALSO KEY-CODE-1 WHEN “1” ALSO 016 DISPLAY “left arrow” WHEN “1” ALSO 014 DISPLAY “right arrow” WHEN “1” ALSO 015 DISPLAY “up arrow” WHEN “1” ALSO 017 DISPLAY “down arrow” END-EVALUATE. STOP RUN.
Additional reference words: 3.00 3.00a Copyright Microsoft Corporation 1993.