检测 Visual Studio 编辑器中的活动
我想知道是否有一个以编程方式连接到 Visual Studio 编辑器的钩子,以便我可以确定是否有人正在编辑器中键入内容。
谢谢!
I would like to know if there is a programmatically hook into the visual studio editor, so that I can determine whether or not someone is typing in the editor.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Visual Studio 中可以通过多种方法来执行此操作。这里有一些不同的可用钩子。
IOleCommandTarget
:Visual Studio 中的击键最终将自身呈现为命令,并通过此链进行路由KeyProcessor
:对于直接 WPF 键盘输入,您可以创建 MEFIKeyProcessorProvider
code> 组件并让创建的KeyProcessor
处理输入ITextBuffer::Changed
:直接侦听底层缓冲区中的更改以解释输入。其中每一个都相当复杂,在一个 SO 问题中为它们添加完整的样本是不合理的。但只要在谷歌中输入他们的名字就可以让你找到正确的方向。
请注意,Visual Studio 中的键盘输入是一个非常复杂的过程。它必须处理 Windows 消息、旧式 Visual Studio 命令、WPF、MEF 挂钩、翻译加速器等……这非常混乱,并且试图在任何一个瓶颈点处理所有输入都充满了问题。我在开发插件时已尽力记录 Visual Studio 键盘输入的当前状态,您可以在这里找到它
但这还不是一个完整的理解。
There are a number of ways to do this in Visual Studio. Here are a few different hooks available.
IOleCommandTarget
: Key strokes in Visual Studio will eventually present themselves as commands and be routed through this chainKeyProcessor
: For straight WPF keyboard input you can creata MEFIKeyProcessorProvider
component and let the createdKeyProcessor
handle the inputITextBuffer::Changed
: Listen directly to changes in the underlying buffer to interpret input.Each of these is fairly complex and adding a full sample for them in an SO question is just not reasonable. But just typing their names into google should get you pointed in the correct direction.
Do note though that keyboard input in Visual Studio is a very complex process. It has to deal with windows messages, old style Visual Studio commands, WPF, MEF hooks, translating accelorators, etc ... It's very messy and trying to tackle all input at any one choke point is fraught with problems. I've done my best to document the current state of Visual Studio keyboard input while working on a plugin and you can find it here
It's hardly a complete understanding though.
绝对有。一堆插件做同样的事情(例如 ViEmu、Resharper 等)。去阅读有关使用 MEF 扩展 VS 编辑器的文档。那里有很多东西,一个简单的谷歌查询就会产生大量结果。
There most definitely is. Stacks of plugins do the same thing (such as ViEmu, Resharper, etc). Go and read the documentation on extending the VS editor using MEF. There's lots of it out there, a simple Google query will yield you plenty of results.