Microsoft KB Archive/124759

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

Article ID: 124759

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft Visual Basic for MS-DOS
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 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.



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: KB124759

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.