KeyBindings 对象 (Word)KeyBindings object (Word)

代表当前上下文中自定义的按键分配方案的**KeyBinding** 对象的集合。A collection of KeyBinding objects that represent the custom key assignments in the current context. 自定义键盘对话框中进行自定义按键分配方案。Custom key assignments are made in the Customize Keyboard dialog box.


KeyBindings 属性用于返回KeyBindings集合。Use the KeyBindings property to return the KeyBindings collection. 以下示例插入所选内容之后的命令名称和组合的每一项 的键绑定 集合中。The following example inserts after the selection the command name and key combination for each item in the KeyBindings collection.

CustomizationContext = NormalTemplate 
For Each aKey In KeyBindings 
 Selection.InsertAfter aKey.Command & vbTab _ 
 & aKey.KeyString & vbCr 
 Selection.Collapse Direction:=wdCollapseEnd 
Next aKey

使用Add方法将KeyBinding对象添加到KeyBindings集合。Use the Add method to add a KeyBinding object to the KeyBindings collection. 下面的示例向活动文档中标题 1 样式的 CTRL + ALT + H 键组合。The following example adds the CTRL+ALT+H key combination to the Heading 1 style in the active document.

CustomizationContext = ActiveDocument 
KeyBindings.Add KeyCategory:=wdKeyCategoryStyle, _ 
 Command:="Heading 1", _ 
 KeyCode:=BuildKeyCode(wdKeyControl, wdKeyAlt, wdKeyH)

使用KeyBindings (Index),其中 Index 是索引号,可返回单个KeyBinding对象。Use KeyBindings (Index), where Index is the index number, to return a single KeyBinding object. 下面的示例显示与 键绑定 集合中的第一个 KeyBinding 对象相关联的命令。The following example displays the command associated with the first KeyBinding object in the KeyBindings collection.

MsgBox KeyBindings(1).Command

另请参阅See also

Word 对象模型引用Word Object Model Reference