KEY n, CHR$(keyboardflag) + CHR$(scancode)
Key Scan Code --- --------- CAPS LOCK &H3A NUM LOCK &H45 SCROLL LOCK &H46By defining traps for NUM LOCK and CAPS LOCK, your program caneffectively reduce (by a factor of four) the number of keys needed tobe defined. For example, to trap both the CTRL+ALT+DEL and CTRL+BREAKkeystroke combinations, 16 keys must be created to handle all thedifferent keystroke combinations. This is more than the maximumnumber of user-defined keys (11). By defining CAPS and NUM LOCKtraps, only 4 additional keys must be defined.
' NOTE: This program assumes NUM LOCK and CAPS LOCK are off at the' beginning. See the article referenced above for how to set' the NUM and CAPS LOCK off.KEY 15, CHR$(&H0) + CHR$(&H3A) ' CAPS LOCKON KEY(15) GOSUB capsKEY(15) ONKEY 16, CHR$(&H0) + CHR$(&H45) ' NUM LOCKON KEY(16) GOSUB numKEY(16) ONKEY 17, CHR$(&H0) + CHR$(&H46) ' SCROLL LOCKON KEY(17) GOSUB scrollKEY(17) ONWHILE INKEY$ <> CHR$(27): WENDENDcaps: PRINT "NO CAPS LOCK TOGGLE!"RETURNnum: PRINT "NO NUM LOCK TOGGLE!"RETURNscroll: PRINT "NO SCROLL LOCK TOGGLE!"RETURN
DEF SEG = 0 X = PEEK(1047) AND 64
DEF SEG = 0 POKE 1047, PEEK(1047) AND 191
DEF SEG = 0 POKE 1047, PEEK(1047) OR 64
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 INS (Insert mode)Although the INS key is included in the table shown above, you cannot makeuse of it. In Visual Basic for MS-DOS, you cannot use either the POKE orthe CALL INTERRUPT to set the Insert mode when you are in Forms mode. Theonly way to set the Insert mode is by pressing the INS key. This is bydesign in Visual Basic for MS-DOS.
PEEK(1047) AND <bval> (where <bval> is the decimal value of the bit that represents the flag you want)To force the flag on (this applies only to the LOCK keys -- not the INSkey), you need to set the appropriate bit. You can do this with thefollowing POKE statement:
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 statement:
POKE 1047, PEEK(1047) AND (255 - <bval>)Note that simply poking the bit value into 1047 would effectively setthe flag, but would also clear all other flags. Thus, be sure toretain the previous values of the other flags by using the abovestrategies.
Article ID: 59132 - Last Review: 08/16/2005 21:25:05 - Revision: 2.1