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

查看:54
本文介绍了如何在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访问鼠标和键盘状态

这为您提供了一个名为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天全站免登陆