如何在MS Word Keypress上举办活动

我正在开发一个MS-Word插件,我的代码必须能够访问用户通过键盘输入的字母。

private void ThisDocument_Startup(object sender, System.EventArgs e) { this.SelectionChange += new SelectionEventHandler(ThisDocument_SelectionChange); } void ThisDocument_SelectionChange(object sender, SelectionEventArgs e) { MessageBox.Show(e.Selection.Text); } 

我认为SelectionChange事件可以给我文本,但事件不是在按键时引发的,有没有办法在按键时触发事件? 此外,如果有更简单的方法或提供function的开源项目,那将是受欢迎的。

Microsoft本身并未公开关键事件,但有一种解决方法。

我在下面链接的文章的帮助下实现了键盘检查:

http://www.switchonthecode.com/tutorials/winforms-accessing-mouse-and-keyboard-state

这为您提供了一个名为IsKeyDown的静态方法,实现和调用您可以订阅的委托应该是相当直接的。