vbdpss.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
Article Q35919
                                                 Contents  Index  Back
─────────────────────────────────────────────────────────────────────────────
                           Knowledge Base Contents  Knowledge Base Index
 
 How to Force CAPS LOCK On or Off with PEEK and POKE - Q35919
 
 This article describes how to programmatically force the CAPS LOCK key
 on or off without actually pressing the CAPS LOCK key.
 
 You can determine the state of the CAPS LOCK key with the following
 PEEK command:
 
    DEF SEG = 0
    X = PEEK(1047) AND 64
 
 If CAPS LOCK is off, the value of "X" will be "0". If CAPS LOCK is on,
 the value will be 64.
 
 To force the CAPS LOCK off, use the following command:
 
    DEF SEG = 0
    POKE 1047, PEEK(1047) AND 191
 
 To force the CAPS LOCK on, use the following:
 
    DEF SEG = 0
    POKE 1047, PEEK(1047) OR 64
 
 More Information:
 
 Each bit of location 1047 reflects the status of a keyboard flag. This
 includes NUM LOCK, SCROLL LOCK, CAPS LOCK, INSert mode, and whether or
 not the LEFT SHIFT and RIGHT SHIFT keys, the ALT key, or the CTRL
 (Control) key is currently pressed or not. See the following table for
 more information:
 
    Bit No.        Decimal Value           Keyboard Flag
    -------         -------------           -------------
 
    0               1                       RIGHT SHIFT
    1               2                       LEFT SHIFT
    2               4                       CTRL (Control)
    3               8                       ALT
    4               16                      SCROLL LOCK
    5               32                      NUM LOCK
    6               64                      CAPS LOCK
    7               128                     INSert mode
 
 To determine the state of any flag, the following command will return
 "0" if the flag is clear (off or not pressed), and will return <bval>
 if the flag is set (on or pressed):
 
    PEEK(1047) AND <bval>
    (where <bval> is the decimal value of the bit that represents the
    flag you want)
 
 To force the flag on (which applies only to the LOCK keys and the
 INSert mode), you need to set the appropriate bit. You can do this
 with the following POKE command:
 
    POKE 1047, PEEK(1047) OR <bval>
    (where <bval> is the decimal value of the flag you want to set)
 
 To force the flag off, you can use the following similar command:
 
    POKE 1047, PEEK(1047) AND (255 - <bval>)
 
 Note that simply poking the bit value into 1047 would effectively set
 the flag, but would also clear all other flags. Therefore be sure to
 retain the previous values of the other flags by using the above
 strategies.
 
 Note that instead of using the PEEK command, you may also get the
 status of keyboard flags with IBM ROM BIOS Interrupt 16h, using
 function number 2. This interrupt returns the ROM BIOS flags byte
 that describes the state of the following keyboard toggles and SHIFT
 keys:
 
 RIGHT SHIFT or LEFT SHIFT key down, CTRL key down, ALT key down,
 SCROLL LOCK on, NUM LOCK on, CAPS LOCK on, INSert on.
 
 Reference(s):
 "Advanced MS-DOS," Ray Duncan, 1986, Microsoft Press