检测 Visual Studio 编辑器中的活动

发布于 2024-09-28 02:38:39 字数 80 浏览 0 评论 0原文

我想知道是否有一个以编程方式连接到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

铃予 2024-10-05 02:38:39

在 Visual Studio 中可以通过多种方法来执行此操作。这里有一些不同的可用钩子。

  • IOleCommandTarget:Visual Studio 中的击键最终将自身呈现为命令,并通过此链进行路由
  • KeyProcessor:对于直接 WPF 键盘输入,您可以创建 MEF IKeyProcessorProvider 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 chain
  • KeyProcessor: For straight WPF keyboard input you can creata MEF IKeyProcessorProvider component and let the created KeyProcessor handle the input
  • ITextBuffer::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.

埋葬我深情 2024-10-05 02:38:39

绝对有。一堆插件做同样的事情(例如 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文