Article ID: 59131 - View products that this article applies to.
This article was previously published under Q59131
Normally, to trap CTRL (CONTROL), ALT, and SHIFT in combination with other keys, you would set the bits for these keys in the first byte (keyboard flag) of the two CHR$() bytes in the KEY statement.
However, to trap the CTRL, ALT, and SHIFT keys alone (not in combination with other keys), the keyboard flag in the KEY statement should be CHR$(0) for the standard keyboard or CHR$(&H80) for keys specific to an extended keyboard.
The syntax of the KEY statement (where n=15 through 25 can be user-defined keys) is as follows:
KEY n, CHR$(keyboardflag) + CHR$(scancode)The following table lists the scan codes for the CTRL, ALT and SHIFT keys:
NOTE: To trap the RIGHT CTRL or RIGHT ALT key (found only on an extended 101 keyboard), the extended keyboard flag (&H80) must be used in the keyboard flag byte.
Key Scan Code --- --------- CTRL &H1D ALT &H38 LEFT SHIFT &H2A RIGHT SHIFT &H36
Code ExampleThe following code example traps the CTRL, ALT, and SHIFT keys alone:
Article ID: 59131 - Last Review: August 16, 2005 - Revision: 2.1
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.