[comp.sys.mac.programmer] How to implement COMMAND-SHIFT-MENUKEY in menus

DFJOHN01@ULKYVX.BITNET (GMAIL_FLAG_PERSONAL_NAME) (05/22/89)

After becoming familiar with a Macintosh program, many users begin to rely
heavily on command key equivalents. In order for the programmer to offer
logically associated command keys, such as "B" for bold, or "B" for send to
back, several applications have utilized a SHIFT option for assigning the
same equivalent to more than one menu item.

So, the question is, how do these programs do it? How do they show the SHIFT
symbol in the menu bar? How do they trap for a COMMAND-SHIFT-MENUKEY in
order to process the correct menu selection?

Any example code showing this nifty enhancement would be greatly appreciated.

Thanks in advance.

David F. Johnson
dfjohn01@ulkyvx

mystone@caen.engin.umich.edu (Dean Yu) (05/22/89)

In article <8905211943.AA01770@jade.berkeley.edu> DFJOHN01@ULKYVX.BITNET (GMAIL_FLAG_PERSONAL_NAME) writes:
>After becoming familiar with a Macintosh program, many users begin to rely
>heavily on command key equivalents. In order for the programmer to offer
>logically associated command keys, such as "B" for bold, or "B" for send to
>back, several applications have utilized a SHIFT option for assigning the
>same equivalent to more than one menu item.
>
>So, the question is, how do these programs do it? How do they show the SHIFT
>symbol in the menu bar? How do they trap for a COMMAND-SHIFT-MENUKEY in
>order to process the correct menu selection?
>

  Actually, this is pretty simple to do.  On a keyDown event, you would
check the event modifier word to see if the shift key and command key was
depressed.  If they were, you'd then parse the key-sequence yourself.  You
can't really call MenuKey to do it for you since MenuKey doesn't distinguish
between cases for command keys.
  The code would look something like

  case myEvent of
	keyDown, autoKey: begin
			    ch:=chr(BitAnd(myEvent.message,charCodeMask));
			    cmdKey:=MenuKey(ch);  
			    if not(cmdKey = 0) then
			       ProcessMenu(cmdKey)
			    else
			       if BitAnd(myEvent.modifiers,shiftKey) = shiftKey
				then
				   ProcessShiftCmd(cmdKey);
			  end;
   end;

  (Please, no flames about how bad the code is.  I just cranked this out off
the top of my head...)

_______________________________________________________________________________
Dean Yu                            | E-mail: mystone@{sol,caen}.engin.umich.edu
University of Michigan             | Real-mail: Dean Yu
Computer Aided Engineering Network |            909 Church St
===================================|            Apt C
"These are MY opinions." (My       |            Ann Arbor, MI 48104
 employer doesn't want them.       |===========================================
 Actually, they don't really care  | 
 what I think.  But President      |   This space intentionally left blank.  
 Duderstadt does...)               | 
-------------------------------------------------------------------------------