Microsoft KB Archive/66687

MS-DOS COBOL 4.00 Can Read Status of SHIFT and Toggle Keys

PSS ID Number: Q66687 Article last modified on 11-18-1990

4.00 MS-DOS

Summary: A COBOL version 4.00 program can read the state of the SHIFT keys (RIGHT SHIFT, LEFT SHIFT, CTRL, and ALT) and the toggle keys (SCROLL LOCK, NUM LOCK, CAPS LOCK, and INS) by calling X“85” and “CBL_AND”. The X“85” subprogram can be used to read the byte value at 0000:1047 (in segment:offset notation). Each bit of that location reflects the status of one of the above keys. The “CBL_AND” subprogram can then be used to check the status of the keys by examining the state of each bit. A code example that will read and display the states of the toggle keys is shown below. This information applies to Microsoft COBOL Professional Development System (PDS) version 4.00 for MS-DOS.

More Information: As mentioned above, each bit of the byte at location 0000:1047 reflects the status of the SHIFT or toggle keys. If the bit is set, the key is down (for the SHIFT keys) or on (for the toggle keys). If the bit is cleared, the opposite condition exists (up for the SHIFT keys, off for the toggle keys). The following is a description of the bits and the keys they represent:

The following example demonstrates how a COBOL 4.00 program can read the status of the toggle keys using X“85” and “CBL_AND”. To exit the program, press the SPACEBAR key.

Code Example
DATA DIVISION. WORKING-STORAGE SECTION. *  Segmented address 0000:1047 (segment:offset) 01 Seg         PIC 9(5)        VALUE 0. 01 Offset      PIC 9(5)        VALUE 1047. *  Receives key-waiting status and next key in keyboard buffer. 01 KeyStat     PIC 99   COMP-X VALUE 0. *  Receives the status of the SHIFT and toggle keys. 01 ToggleStat  PIC 99   COMP-X. *  Used to loop through the values for the toggle keys. 01 ToggleKey   PIC 99   COMP-X. *  The bits used to compute value of ToggleKey (2**Power). 01 Power       PIC 99   COMP-X. PROCEDURE DIVISION. *   Clear the screen and show a list of the toggle keys. CALL X&quot;E4&quot;. DISPLAY &quot;SCROLL LOCK :&quot; AT 0401. DISPLAY &quot;NUM LOCK    :&quot; AT 0501. DISPLAY &quot;CAPS LOCK   :&quot; AT 0601. DISPLAY &quot;INS     :&quot; AT 0701. *   Loop until the space-bar is hit. PERFORM UNTIL KeyStat = 32 *      Check if a key is waiting in the buffer. CALL X&quot;D9&quot; USING KeyStat *      If a key is waiting, read it. IF KeyStat NOT = 0 THEN CALL X&quot;83&quot; USING KeyStat END-IF *      Read the status of the SHIFT and toggle keys. CALL X&quot;85&quot; USING Seg, Offset, ToggleStat *      Loop through the different bits for the toggle keys. PERFORM VARYING Power FROM 4 BY 1 UNTIL Power > 7 *         Compute the bit value for the toggle key. COMPUTE ToggleKey = 2**Power *         Check if the toggle keys bit is set or not. CALL &quot;CBL_AND&quot; USING ToggleStat, ToggleKey BY VALUE 1 *         Change the status of the toggle key accordingly. IF ToggleKey NOT = 0 THEN DISPLAY &quot;ON &quot; AT LINE Power COLUMN 14 ELSE DISPLAY &quot;OFF&quot; AT LINE Power COLUMN 14 END-IF END-PERFORM END-PERFORM STOP RUN. For a separate article describing how to change the status of SHIFT and toggle keys, search for the following words in this Knowledge Base: COBOL and change and SHIFT and toggle and status and 86

Copyright Microsoft Corporation 1990.