How to Trap CTRL+BREAK, CTRL+C on Standard & Enhanced Keyboard

ID: Q33034


The information in this article applies to:
  • Microsoft Visual Basic Standard and Professional Editions for MS-DOS, version 1.0
  • Microsoft QuickBASIC for MS-DOS, version 4.5
  • Microsoft BASIC Compiler for MS-DOS and MS OS/2, versions 6.0, 6.0b
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2, version 7.0


SUMMARY

The scan code for the BREAK key is &H46. The CTRL+BREAK keystroke combination is trapped differently, depending on whether or not the program is run on a standard or enhanced keyboard.

This information is also included with the Help file provided with the Standard and Professional Editions of Microsoft Visual Basic for MS-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 statements for trapping CTRL+BREAK in combination with the SHIFT, ALT, NUM LOCK, and CAPS LOCK keys. The keyboard flags for these other keystroke combinations must be added together to define a given keystroke sequence.

Examples of trapping CTRL+BREAK and CTRL+C (when the SHIFT, ALT, NUM LOCK, or CAPS LOCK keys are NOT active) are included below.


MORE INFORMATION

Use the following steps to execute the examples listed below in VBDOS.EXE:

  1. From the File menu, choose New Project.


  2. Copy the code example to the Code window.


  3. 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) ON
KEY(16) ON
ON KEY(16) GOSUB trap
ON KEY(15) GOSUB trap
FOR i = 1 TO 500
   PRINT i
NEXT
END
trap:
   PRINT "trapped"
   RETURN 
NOTE: If NUM LOCK, SCROLL LOCK, or CAPS LOCK is on, this example will not work. For additional information on how to disable these keys, please see the following article(s) in the Microsoft Knowledge Base:
Q59132 How to Disable Toggle for NUM/CAPS/SCROLL LOCK with Key Trap

Additional query words: VBmsdos QuickBas BasicCom 2.00 2.10 3.00 4.00 4.00b 4.50

Keywords :
Version : MS-DOS:1.0,4.5; :6.0,6.0b,7.0
Platform : MS-DOS
Issue type :


Last Reviewed: December 8, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.