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 "COMMAND key is"; LOCATE 2,1 : PRINT "SHIFT key is"; LOCATE 3,1 : PRINT "CAPS LOCK key is"; LOCATE 4,1 : PRINT "OPTION key is"; LOCATE 6,1 : PRINT "PEEK(378)="; LOCATE 6,1 : PRINT "PEEK(379)="; ' Loop until user presses any key other than the above four: WHILE INKEY$ = "" p1 = PEEK(378) p2 = PEEK(379) LOCATE 1,15 ' PRINT the setting of the COMMAND key: IF p1=128 THEN PRINT "down"; ELSE PRINT "up"; LOCATE 2,15 ' PRINT the setting of the SHIFT key: IF p2=1 OR p2=3 OR p2=5 OR p2=7 THEN PRINT "down"; ELSE PRINT 'up"; 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 "down"; ELSE PRINT 'up"; LOCATE 4,15 ' PRINT the setting of the OPTION key: IF p2=4 OR p2=5 OR p2=6 OR p2=7 THEN PRINT "down"; ELSE PRINT 'up"; 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