Lon McQuillin wrote: > Last year I posed a question regarding adding an up arrow key graphic > in the File menu in the Save As... dialog, and Ben Jamin kindly > responded with the menu mod routine that added the graphic. > > As I posted a few days later, however, I couldn't figure out where > within a PG-structured program to trap the Shift-Command-S keystrokes. > When the text edit window is open and there have been no changes, my > before menu routine will properly set Save to disabled and Save As... > to enabled, and again, if the menus are selected with the mouse > everything works fine. > > Ben again responded last year, but it was with kind of a standalone > mini application to handle the problem, where I need to insert > something into a legacy PG4/FBII project. > I know this must be simple, but I'm a bit rusty on PG-structured FB > these days. Where in my MAIN or perhaps in FLTRs would I trap for > this key combination? I acknowledge no equal in my ignorance of PG, but seem to remember that it's built on top of the Standard BASIC runtime. It therefore inherits an obsolete method of matching command-key strokes with menus, namely MenuKey. "MenuKey maps a character key with the Command key to determine the keyboard equivalent of a menu item in a menu in the current menu list." The Appearance runtime uses the newer MenuEvent. "MenuEvent maps a keyboard combination from the event structure to the keyboard equivalent of a menu item in a menu in the current menu list. Unlike MenuKey, the MenuEvent function supports the Shift, Option, and Control modifier keys in addition to the Command key." To get Standard BASIC to interpret correctly a key combination such as Command-shift-s, you have to install a raw event handler (DoEvent in the demo) that detects key-down events with the command modifier, calls MenuEvent, and notifies the runtime of a menu choice. How you would make this work in PG I do not know; it should be possible though. Below is a demo that works the same in Standard BASIC or Appearance. Typing Command-shift-s displays Menu: 1 item: 6 Robert P. '---------------------- #if ( ndef _appearanceRuntime ) toolbox fn MenuEvent( @EventRecord ) = long toolbox fn SetMenuItemModifiers( Handle, short, short ) = OSErr _kMenuShiftModifier = (1 << 0) #endif begin enum 1 _mFile end enum begin enum 1 _iNew _iOpen _iFSeparator1 _iClose _iSave _iSaveAs _iFSeparator2 _iQuit end enum local fn SetupMenus '~'1 dim as MenuRef menuH dim as OSErr ignore menu _mFile, 0, 1, "File" menu _mFile, _iNew, 1, "New/N" menu _mFile, _iOpen, 1, "Open…/O" menu _mFile, _iFSeparator1, 0, "-" menu _mFile, _iClose, 1, "Close/W" menu _mFile, _iSave, 1, "Save/S" menu _mFile, _iSaveAs, 1, "Save As…/S" menu _mFile, _iFSeparator2, 0, "-" menu _mFile, _iQuit, 1, "Quit/Q" menuH = fn GetMenuHandle( _mFile ) ignore = fn SetMenuItemModifiers( menuH, _iSaveAs, _kMenuShiftModifier ) end fn local fn DoMenu '~'1 dim as short menuNum, menuItem menuNum = menu(0) menuItem = menu(1) if ( menuNum == _mFile and menuItem == _iQuit ) then end print "Menu: "menuNum, "item: " menuItem menu end fn #if ( ndef _appearanceRuntime ) // override Standard BASIC runtime command key handler local fn DoEvent '~'1 dim ev as ^EventRecord dim as long theMenuKey ev = event long if ( ev.what == _keyDwnEvt ) long if ( ev.modifiers and _cmdKey% ) theMenuKey = fn MenuEvent( #ev ) long if ( theMenuKey ) // convert to menu event fn FBMenuSelected( theMenuKey>>16, theMenuKey and 0xFFFF ) ev.what = 0 // null out this event end if end if end if end fn // install event handler on event fn DoEvent #endif fn SetupMenus on menu fn DoMenu window 1 do HandleEvents until 0 '----------------------