Assign an Accelerator Key to a Menu Item
 
 
 

To assign the accelerator key for a menu item through AutoCAD ActiveX/VBA, use the Label property of the given menu item. To specify an accelerator key, insert the ASCII equivalent of an ampersand (&) in the label directly in front of the character to be used as the accelerator. For example, the label Chr(Asc("&")) + "Edit" will be displayed as “Edit,” with the character “E” being used as the accelerator key.

Add accelerator keys to menus

This example repeats the example from Add menu items to a popup menu, adding accelerator keys for both the “TestMenu” and “Open” menus. The “s” is used as the accelerator key for the “TestMenu” menu and the “O” is used as the accelerator key for the “Open” menu.

Sub Ch6_AddAMenuItem()
	Dim currMenuGroup As AcadMenuGroup
	Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)


	' Create the new menu
	Dim newMenu As AcadPopupMenu
	Set newMenu = currMenuGroup.Menus.Add _
							("Te" + Chr(Asc("&")) + "stMenu")


	' Add a menu item to the new menu
	Dim newMenuItem As AcadPopupMenuItem
	Dim openMacro As String
	' Assign the macro the VBA equivalent of "ESC ESC _open "
	openMacro = Chr(3) + Chr(3) + "_open "


	Set newMenuItem = newMenu.AddMenuItem _
					 (newMenu.count + 1, Chr(Asc("&")) _
						+ "Open", openMacro)


	' Display the menu on the menu bar
	newMenu.InsertInMenuBar _
				 (ThisDrawing.Application.menuBar.count + 1)
End Sub