Keyboard Shortcut System

3DS Max Plug-In SDK

Keyboard Shortcut System

Class ShortcutTable, Class ShortcutOperation, Class ShortcutCallback

Important Note: A new system to handle keyboard accelerators was added for R4. This system supercedes those used in previous release. For information on this system see the class ActionTable. The information shown below applies to previous version of the SDK APIs.

Overview

The following is a discussion of the plug-in definable keyboard shortcut system avaialbe in release 3.0 and later. The pre-R3 system remains in place for backwards compatability.

The keyboard preferences dialog has been expanded to allow the editing of keyboard shortcuts for plug-ins. There is a new radio button added to the set of shortcuts, labeled "Plug-Ins". When this is selected a drop-down list next to the button is activated which lists all the plug-ins that have registered keyboard shortcut tables. After selecting one from the drop-down list, you can change the shortcuts in the same way the main UI shortcuts are changed. This provides a clean way for all plug-ins to make their keyboard shortcuts available in a uniform manner.

The basic process works like this: A developers assigns an ID and name to each shortcut (these are stored in a Shortcut Description). The ID identifies the each shortcut and the name appears in the 3ds max user interface where the shortcuts are assigned to keys by the user. An array of these shortcuts is used to make up something called a Shortcut Table. This table stores and provides access to the shortcut data. These data items are referred to as Shortcut Operations.

A developer provides 3ds max with the shortcut table data for a plug-in at Dll load time using two new methods of the Class Descriptor. These methods return the number of shortcut tables used by the plug-in and return a pointer to the 'i-th' table. These methods are ClassDesc::NumShortcutTables() and ClassDesc::GetShortcutTable(int i).

The tables become active and inactive as a whole by using two method provided by the Interface class. These are ActivateShortcutTable() and DeactivateShortcutTable(). These will normally be called by a developer inside BeginEditParams() and EndEditParams().

Principal Classes

The following is a overview of the principal classes and structures involved in making this happen:

Class ShortcutTable: This class provides storage for and access to the ShortcutOperations.

Class ShortcutOperation: This class describes an operation that can be attached to a keyboard shortcut. There is an ID sent to the window proc when the shortcut is executed, a name for the operation that appears in the 3ds max user interface where the shortcuts are assigned.

Class ShortcutCallback: When the user presses a shortcut key that is assigned in an active table, it calls this classes KeyboardShortcut(int id) method with the id of the operation. Here the plug-in should execute the operation. If the state of the plug-in is such that the operation should not be performed it can return FALSE from this method. In this case any system defined shortcut will be executed instead. If the plug-in returns TRUE then only the plug-in defined shortcut is executed. A developer dervies a class from this class and passes an instance of it to the method Interface::ActivateShortcutTable().

Structure ShortcutDescription: This structure provides a description of a command for building shortcut tables from static data. The structure holds the command ID that is sent to ShortcutCallback::KeyboardShortcut() method and a resource ID for the string that describes the shortcut. A pointer to an array of these is passed to the ShortcutTable constructor.

Class ClassDesc: Two methods have been added to this class that are called at Dll load time to get the shortcut table(s) from the plug-in.

Class Interface: There are new functions added to this class to activate and deactivate a shortcut table. These are normally called by a plug-in in BeginEditParams() and EndEditParams(). There are also methods that allow one to access the names and command IDs from a specific keyboard shortcut table. See Keyboard Shortcut Table Related Methods in class Interface.

Sample Code

For an example of using this mechanism see the code in the directory \MAXSDK\SAMPLES\MODIFIERS\FFD.