How to Trap CTRL+UP and CTRL+DOWN Arrow Key Sequences

ID: Q124759


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 Professional Development System (PDS) for MS-DOS and MS OS/2, versions 7.0, 7.1


SUMMARY

This article gives an example showing how to capture the key sequences of the CTRL key with the UP and DOWN arrow keys. It involves defining new keys that are equivalent to the key sequence and then trapping them. The CTRL key is defined by the constant &H4, the UP arrow key by 72, and the DOWN arrow key by 80.

Please note that you must make separate user-defined KEY statements for trapping CTRL+UP and CTRL+DOWN 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.


MORE INFORMATION

Code Example

The following code shows by example how to trap the CTRL+UP and CTRL+DOWN arrow keys when the SHIFT, ALT, NUM LOCK, or CAPS LOCK keys aren't active.

     CONST CTRLFLAG = &H4     'define constants
   CONST UPARROW = 72
   CONST DOWNARROW = 80

'Setup keys to trap, and turn on the trapping
   KEY 15, CHR$(CTRLFLAG) + CHR$(UPARROW)
   KEY 16, CHR$(CTRLFLAG) + CHR$(DOWNARROW)
   ON KEY(15) GOSUB GotUp
   ON KEY(16) GOSUB GotDown
   KEY(15) ON
   KEY(16) ON

   WHILE INKEY$ <> "Q"     'sit in loop and wait for keypresses
   WEND
   END

GotUp:
   PRINT "Ctrl-Up"
   RETURN

GotDown:
   PRINT "Ctrl-Down"
   RETURN 

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; :7.0,7.1
Platform : MS-DOS
Issue type :


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