本文介绍了捕获MS Word的keydown事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想捕获backspace事件,只需执行backspace的操作,然后添加其他操作,但我不确定backspace的原始操作:Selection。删除,-1?
I want to capture the backspace event, just do the backspace's action, then add other action, but I am not sure the backspace's original action:Selection. Delete , -1 ?
Sub AddKeyBinding()
With Application
' \\ Do customization in THIS document
.CustomizationContext = ThisDocument
' \\ Add keybinding to this document Shorcut: Backspace
.KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyBackspace), _
KeyCategory:=wdKeyCategoryCommand, Command:="TestKeybinding"
End With
End Sub
' \\ Test sub for keybinding
Sub TestKeybinding()
Selection.Delete , -1 ' I am not sure how to impl the original command
If Selection.Style = "Some...Style" And Selection.Range.ListFormat.ListString = "" Then
Selection.Style = "DefaultStyle"
End If
End Sub
推荐答案
最后,我尝试使用autohotkey来解决这个问题,一些代码如下:
At last I try use autohotkey to solve this question,some code like down:
#IfWinActive,ahk_class OpusApp
;回车键
enter::
send {enter}
checkStyle()
return
backspace::
send {backspace}
checkStyle()
return
checkStyle(){
word:=ComObjActive("word.application")
if(word.Selection.Style.NameLocal="ListItemStyle" and word.Selection.Range.ListFormat.ListString = "")
{
word.Selection.Style := "someStyle"
TrayTip, hint, style chnaged, 3, 17
}
}
这篇关于捕获MS Word的keydown事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!