Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!hoptoad!tim From: tim@hoptoad.uucp (Tim Maroney) Newsgroups: comp.sys.mac.programmer Subject: A replacement for MenuKey Message-ID: <9715@hoptoad.uucp> Date: 17 Jan 90 14:53:30 GMT Organization: Eclectic Software, San Francisco Lines: 68 MenuKey has the irritating property of making assumptions about the shift and option key which are hard to fathom. Basically, it does some sort of transformation on the menu shortcut or on the character you pass it which converts lowercase keys to uppercase and sometimes turns them into their "no option key" forms. So I wrote a replacement which checks the menus itself in what should be a compatible fashion. Now you can put option-key shortcuts into your menus, as well as differentiating between the shifted and unshifted versions of punctuation keys. MyMenuKey assumes the Script Manager is installed; if you want to run it on pre-System-6.0 (you fool, why would you want do that? Get some new ROMs!) you will have to hack in some non-SM code. The code also makes certain assumptions about your menus, which may need modification for your own code. My menus start at id 1 and go up contiguously from there. You may need to do some other form of iteration for the main loop, but the inner loop and the preface should still work fine. Now, it someone would contribute an MDEF 0 replacement that will display the shortcuts in a better form (they currently appear as the option-key characters, not in the somewhat better MacroMaker format), we'd really have something going. (By the way, it looks as if I will have to be in Boston for a few days almost immediately. It is not a social occasion, but nevertheless, if you have corresponded with me here and want to have a meal, and can put up with what will probably not be one of my best moods, then leave me a message and I hope I get it in time. I only mention this because a couple of you expressed regret that you missed me in Boston over Labor Day weekend.) long MyMenuKey(EventRecord *event) { MenuHandle menu; short i, j, code, limit, cmd, state, type; long trans, kstate = 0; Handle kchr; char c; if ((kchr = GetIndResource('KCHR', 1)) == 0) return MenuKey(event->message & 0xff); c = event->message & 0xff; type = CharType(&c, 0) & 7; code = (event->message & 0xff00) >> 8; if ((event->modifiers & optionKey) == 0 && type != smCharPunct) code |= shiftKey; else if ((event->modifiers & optionKey) == 0 && type == smCharPunct) code |= event->modifiers & shiftKey; else if (event->modifiers & optionKey) code |= optionKey; state = HGetState(kchr); HLock(kchr); HNoPurge(kchr); trans = KeyTrans(*kchr, code, &kstate); HSetState(kchr, state); c = trans & 0xff; for (i = 1, menu = GetMHandle(i); menu; i++, menu = GetMHandle(i)) { limit = CountMItems(menu); for (j = 1; j <= limit; j++) { GetItemCmd(menu, j, &cmd); if (cmd == c) { HiliteMenu(i); return ((long)i << 16) | j; } } } return MenuKey(event->message & 0xff); } -- Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com "I was bitter when I met you, I was eloquent with rage...." -- Annie Lennox