How to Trap CTRL+UP and CTRL+DOWN Arrow Key Sequences (124759)



The information in this article applies to:

  • Microsoft Visual Basic for MS-DOS
  • Microsoft QuickBASIC 4.5
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.1

This article was previously published under Q124759

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
				

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB124759