How to Make COMMAND+Key Alternatives to MENUs in BASIC (57778)






This article was previously published under Q57778

SUMMARY

To make COMMAND+key options serve as an alternative to selecting user-defined MENUs with the mouse, you can use the CMDKEY statement (an MBLC Toolbox library routine). The CMDKEY statement also automatically places the special COMMAND-key-character symbol in the menu item (see the code example below). This information applies to Microsoft QuickBASIC Version 1.00 for the Apple Macintosh.

MORE INFORMATION

The CMDKEY Toolbox library statement is described on Page 477 of the "Microsoft QuickBASIC for Apple Macintosh: Language Reference" manual.

Code Example

This example is based on the MenuKeys sample program, located in the Programs Folder in the MS ToolLib Folder on Disk 2 (the BASIC ToolBox Disk) of Microsoft BASIC Compiler Version 1.00 for the Apple Macintosh, and in the same location on the BASIC ToolBox Disk for Microsoft BASIC Interpreter Version 3.00 for the Apple Macintosh. These products are the precursors to QuickBASIC, and the features are similar. To make the program below match MenuKeys and work in these earlier BASIC products, just add the statement LIBRARY "BASIC Toolbox:ToolLib" at the top.

When you run this program, press COMMAND+B to select the Bold menu item, or press COMMAND+I to select the Italic menu item.
TEXTMODE 10
FOR n=1 TO 5
   MENU n,0,0,""
NEXT n
MENU 1,0,1,"File"
MENU 1,1,1,"Quit"
CmdKey 1,1,"Q"
MENU 2,0,1,"Print"
MENU 2,1,1,"Bold"
MENU 2,2,1,"Italic"
CmdKey 2,1,"B"         ' Press COMMAND+B for bold.
CmdKey 2,2,"I"         ' Press COMMAND+I for italic.
SetItemStyle 2,1,1
SetItemStyle 2,2,2
ON MENU GOSUB event
MENU ON
delay:
   GOTO delay
END
event:
   MENU
   men=MENU(0)
   item=MENU(1)
   IF men=1 THEN STOP
   TEXTFACE item
   PRINT"This is the style you chose"
RETURN
				

Modification Type: Minor Last Reviewed: 1/9/2003
Keywords: KB57778