如何使用C#检测单词VSTO加载项中的按键事件? [英] How to detect keypress events in word VSTO add-in using C#?

查看:199
本文介绍了如何使用C#检测单词VSTO加载项中的按键事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单,因为我想检测按键事件,例如 KeyUp KeyDown 在Visual Studio2015中使用C#进行开发时的VSTO单词加载项中的KeyPress 并按 KeyCode 运行其他函数。



根据MSDN文档,VSTO加载项没有此类事件,但它们正在为其他一些事件提供类似Document.SelectionChange事件 ApplicationEvents4_Event.WindowSelectionChange事件但它们不符合要求。



那么有没有办法按照我的问题以简单的方式使用C#... ???



我尝试过的事情:



StackOverflow上有很多相关的问题,但根据我的问题没有一个问题。



从VSTO加载项检测Word 2016中的文本更改

C#中MS Word的加载项TextChange事件

如何从Word 2010 Addin(用C#开发)获取KeyPress事件?

捕获keydown使用C#的MS Word事件

如何在MS word Keypress上举办活动

如何使用VSTO捕获MSword中的按键事件?

My question is simple as I want to detect key press events like KeyUp, KeyDown, KeyPress in VSTO Words Add-In while development using C# in VisualStudio2015 and run other functions as per KeyCode.

As per MSDN documentation, there are no such events for VSTO Add-In but they are giving some others events thats are like them as Document.SelectionChange Event and ApplicationEvents4_Event.WindowSelectionChange event but they are not as per requirements.

So is there any way to make it as per my question in easy way using C#...???

What I have tried:

There are many related questions asked on StackOverflow but none of them is as per my question.

Detecting text changes in Word 2016 from VSTO add-in
MS Word's Add-in TextChange Event in C#
How to get the "KeyPress" event from a Word 2010 Addin (developed in C#)?
Capturing keydown event of MS Word using C#
How to raise an event on MS word Keypress
How to trap keypress event in MSword using VSTO?

推荐答案

您将不得不挂钩窗口的键盘事件。要在C#中执行此操作,您需要通过Interop Services使用Windows API。 pinvoke.net网站可以帮助您找到合适的API函数原型和常量,但您必须在谷歌上进行一些挖掘,以了解如何将它们放在一起。
You're going to have to hook the keyboard events for the window. To do that in C#, you need to use the Windows API via Interop Services. The pinvoke.net website can help you find the appropriate API function prototypes and constants, but you'll have to do some digging on google to find out how to put it all together.


这篇关于如何使用C#检测单词VSTO加载项中的按键事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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