Assigning Key Sequences to Add-in Commands Programmatically

Home Page (Add-ins)OverviewHow Do I ... TopicsFAQReference

The user can carry out an add-in command by using a key sequence assigned to the command. The user can assign this key sequence through the user interface, or you can assign it programmatically.

To assign a key sequence programmatically

  1. Open the project for the add-in.

  2. In ClassView, expand the project's classes, and then expand the CDSAddIn class.

  3. Double-click the OnConnection method.

  4. Search for code that adds the command. This code calls the AddCommand method.

  5. After the AddCommand call, insert a call to the AddKeyBinding method so that Developer Studio calls AddKeyBinding only when the bFirstTime parameter of the OnConnection method has a value of VARIANT_TRUE.

    The bFirstTime parameter directs Developer Studio to call AddKeyBinding only when the user first connects the add-in to the development environment.

Caution   Unless key sequences are necessary, do not add them because they might replace existing ones. For example, if a keystroke is assigned to a command and you assign the same keystroke to another command, your new assignment replaces the original. For best results, let the user assign key sequences to the commands added by an add-in.

Additionally, Visual C++ provides other ways of using key sequences to customize your desktop environment. For details, see Overview: Customizing Visual C++.

See Also   Assigning Key Sequences to Add-in Commands Visually, Creating Toolbar Buttons for Add-in Commands Programmatically