Microsoft KB Archive/36894

= Predefined Key ON KEY(n) GOSUB Trap Supersedes User-Defined =

Article ID: 36894

Article Last Modified on 11/18/2003

-

APPLIES TO


 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft BASIC Professional Development System 7.0

-



This article was previously published under Q36894



SUMMARY
If a predefined key (such as a key from n=1 through 14) is turned on, the associated ON KEY(n) GOSUB statement is executed regardless of the status of the keyboardflag. In other words, a predefined key is trapped whether or not the key is pressed alone or in conjunction with the CAPS LOCK, NUM LOCK, SHIFT, CTRL, or ALT keys. The key trap occurs even if the same key also is defined with a specific keyboardflag value in a user-defined KEY statement. (User-defined keys are from n=15 through 20 in QuickBasic Versions 3.00 and earlier, and from n=15 to 25 in QuickBasic Versions 4.00 and later and Basic compiler Versions 6.00 and 6.00b for MS-DOS and OS/2.)

Unlike trapping predefined keys, trapping user-defined keys IS dependent on the status of CAPS LOCK, NUM LOCK, SHIFT, CTRL, or ALT key.



MORE INFORMATION
In the code example below, the user-defined key trap for CTRL+F1 initially works as expected. If you press F2 and turn on the trapping of predefined function KEY (1), then the user-defined key trap for CTRL+F1 is ignored. The ON KEY (1) GOSUB trap for predefined function key 1 takes priority. This behavior is by design.

This information applies to all versions of QuickBasic, to Microsoft Basic Compiler Versions 6.00 and 6.00b for MS-DOS and MS OS/2, and to Microsoft Basic PDS Version 7.00 for MS-DOS and MS OS/2.

The following is a code example: ON KEY(1) GOSUB got1 KEY(1) OFF ON KEY(2) GOSUB swapper KEY(2) ON KEY 16, CHR$(4) + CHR$(&H3B) ON KEY(16) GOSUB got16 KEY(16) ON print &quot;Press an F1, CTRL-F1, or F2 key&quot; WHILE 1 WEND END

got16: PRINT &quot;found user-defined CTRL-F1 &quot; RETURN

got1: PRINT &quot;found predefined F1 &quot; RETURN

swapper: INPUT &quot;set Predefined on (Y/n) &quot;, a$  IF a$ = &quot;N&quot; or a$=&quot;n&quot; THEN KEY(1) OFF ELSE KEY(1) ON  END IF RETURN

Additional query words: QuickBas BasicCom

Keywords: KB36894

-

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

© Microsoft Corporation. All rights reserved.