如何在 MS word Keypress 上引发事件 [英] How to raise an event on MS word Keypress

查看:19
本文介绍了如何在 MS word Keypress 上引发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am developing a MS-Word addon in which my code has to get access to the letters the user is entering through the keyboard.

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 事件可以给我文本,但在按键时不会引发该事件,有什么办法可以在按键时触发该事件?此外,如果有更直接的方法来实现它或提供该功能的开源项目,那将是受欢迎的.

I think the SelectionChange event can give me the text but the event is not raised at keypress, Is there any way to trigger the event at keypress? Also if there is a more straightforward way to do it or an open source project that give the functionality, it would be welcome.

推荐答案

Microsoft 本身不会公开按键按下事件,但有一个解决方法.

Microsoft doesn't expose a key down event natively, but there's a workaround.

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

I implemented keyboard checking with help from the article linked below:

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

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

This gives you a static method called IsKeyDown, implementing and invoking a delegate you can subscribe to should be fairly straight forward.

这篇关于如何在 MS word Keypress 上引发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆