Microsoft KB Archive/51658

= How to PEEK Status of COMMAND, SHIFT, CAPS LOCK, OPTION Keys =

Article ID: 51658

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft QuickBasic Compiler for Macintosh 1.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft BASIC Interpreter 2.0
 * Microsoft BASIC Interpreter 2.1 for Macintosh
 * Microsoft BASIC Interpreter 3.0 for Macintosh

-



This article was previously published under Q51658



SUMMARY
This article provides a sample program where the PEEK function returns the up (inactive) or down (active) status of the COMMAND, SHIFT, CAPS LOCK, and OPTION keys for Apple Macintosh computers. You can poll the PEEK function in a loop to detect the changing status of these keys.



MORE INFORMATION
PEEKing address 378, found in low Macintosh memory, returns a 128 if the COMMAND key is currently down (active), or 0 (zero) if the COMMAND key is currently up (not active).

PEEKing address 379 returns 1 if SHIFT is down, 2 if CAPS LOCK is down, or 4 if OPTION is down. The values are added together if more than one key is down at once. A key that is up (not active) adds nothing (zero). For example, if the SHIFT (value 1) and CAPS LOCK (value 2) keys are both down, and the OPTION key is up (value 0), then PEEK(379) returns a 3 (since 1, 2, and 0 are added together).

Code Example
LOCATE 1,1 : PRINT &quot;COMMAND key is&quot;; LOCATE 2,1 : PRINT &quot;SHIFT key is&quot;; LOCATE 3,1 : PRINT &quot;CAPS LOCK key is&quot;; LOCATE 4,1 : PRINT &quot;OPTION key is&quot;; LOCATE 6,1 : PRINT &quot;PEEK(378)=&quot;; LOCATE 6,1 : PRINT &quot;PEEK(379)=&quot;; ' Loop until user presses any key other than the above four: WHILE INKEY$ = &quot;&quot;

p1 = PEEK(378) p2 = PEEK(379) LOCATE 1,15  ' PRINT the setting of the COMMAND key: IF p1=128 THEN PRINT &quot;down&quot;; ELSE PRINT &quot;up&quot;; LOCATE 2,15  ' PRINT the setting of the SHIFT key: IF p2=1 OR p2=3 OR p2=5 OR p2=7 THEN PRINT &quot;down&quot;; ELSE PRINT 'up&quot;; LOCATE 3,15  ' PRINT the setting of the CAPS LOCK key: IF p2=2 OR p2=3 OR p2=6 OR p2=7 THEN PRINT &quot;down&quot;; ELSE PRINT 'up&quot;; LOCATE 4,15  ' PRINT the setting of the OPTION key: IF p2=4 OR p2=5 OR p2=6 OR p2=7 THEN PRINT &quot;down&quot;; ELSE PRINT 'up&quot;; LOCATE 6,10 : PRINT p1;  ' Prints value of PEEK(378) LOCATE 7,10 : PRINT p2;  ' Prints value of PEEK(379)

Additional query words: BasicCom MQuickB

Keywords: KB51658

-

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

© Microsoft Corporation. All rights reserved.