This article was previously published under Q33034
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
The scan code for the BREAK key is &H46. The CTRL+BREAK keystrokecombination is trapped differently, depending on whether or not theprogram is run on a standard or enhanced keyboard.
This information is also included with the Help file provided with theStandard and Professional Editions of Microsoft Visual Basic forMS-DOS, version 1.0.
For a standard keyboard, CTRL+BREAK is defined as follows
KEY n, CHR$(&H04) + CHR$(&H46)
where n is in the range 15 through 25.
On an enhanced keyboard, CTRL+BREAK is defined as follows:
KEY n, CHR$(&H84) + CHR$(&H46)
Please note that you must make separate user-defined KEY statementsfor trapping CTRL+BREAK in combination with the SHIFT, ALT, NUM LOCK,and CAPS LOCK keys. The keyboard flags for these other keystrokecombinations must be added together to define a given keystrokesequence.
Examples of trapping CTRL+BREAK and CTRL+C (when the SHIFT, ALT,NUM LOCK, or CAPS LOCK keys are NOT active) are included below.
Use the following steps to execute the examples listed below inVBDOS.EXE:
From the File menu, choose New Project.
Copy the code example to the Code window.
Press F5 to run the program.
Code Example 1
KEY 15, CHR$(&H84) + CHR$(&H46) ' Traps CTRL+BREAK on enhanced keyboard.KEY 16, CHR$(&H4) + CHR$(&H46) ' Traps CTRL+BREAK on standard keyboard.KEY(15) ONKEY(16) ONON KEY(16) GOSUB trapON KEY(15) GOSUB trapFOR i = 1 TO 500 PRINT iNEXTENDtrap: PRINT "trapped" RETURN
NOTE: If NUM LOCK, SCROLL LOCK, or CAPS LOCK is on, this example will notwork. For additional information on how to disable these keys, please seethe following article(s) in the Microsoft Knowledge Base:
59132 How to Disable Toggle for NUM/CAPS/SCROLL LOCK with Key Trap