Microsoft KB Archive/39252

= ON KEY Trapping CTRL, SHIFT, CAPS LOCK, NUM LOCK Combinations =

Article ID: 39252

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1

-



This article was previously published under Q39252



SUMMARY
Pressing any key in combination with CTRL, SHIFT, ALT, CAPS LOCK, or NUM LOCK changes the keyboard scan code. To trap combinations of keys, the KEY statement requires adding together the values of the keyboard flags as shown in the code example below.



MORE INFORMATION
The following is a code example: CONST alt = &H8 CONST noflag = &H0 CONST leftshift = &H1 CONST rightshift = &H2 CONST ctrl = &H4 CONST numlock = &H20 CONST capslock = &H40 CONST extendedkeyboard = &H80 CONST left = &H4B CONST right = &H4D CONST up = &H48 CONST down = &H50 CONST C = &H2E CONST scrolllock = &H46

KEY 15, CHR$(extendedkeyboard + numlock) + CHR$(left) KEY 16, CHR$(extendedkeyboard + numlock) + CHR$(right) KEY 17, CHR$(extendedkeyboard + numlock) + CHR$(up) KEY 18, CHR$(extendedkeyboard + numlock) + CHR$(down) KEY 19, CHR$(ctrl + capslock) + CHR$(C) KEY 20, CHR$(extendedkeyboard + ctrl + numlock) + CHR$(scrolllock)

ON KEY(15) GOSUB left ON KEY(16) GOSUB right ON KEY(17) GOSUB up  ON KEY(18) GOSUB down ON KEY(19) GOSUB break ON KEY(20) GOSUB break

KEY(15) ON  KEY(16) ON   KEY(17) ON   KEY(18) ON   KEY(19) ON   KEY(20) ON

WHILE UCASE$(INKEY$) <> UCASE$(&quot;q&quot;) WEND END

left: PRINT &quot;left&quot; RETURN

right: PRINT &quot;right&quot; RETURN

up: PRINT &quot;up&quot; RETURN

down: PRINT &quot;down&quot; RETURN

break: PRINT &quot;break&quot; RETURN

Additional query words: QuickBas BasicCom

Keywords: KB39252

-

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

© Microsoft Corporation. All rights reserved.