Visual Studio 扩展的动态热键

发布于 2025-01-01 01:03:45 字数 193 浏览 2 评论 0原文

有什么方法可以从 Visual Studio 扩展/包中动态添加全局热键吗?

在我的包的 *.vsct 文件中声明热键是没有选择的,因为我不知道哪些热键应该在运行时可用 - 我的扩展中有一种插件系统可以动态添加/删除热键。

添加消息过滤器仅在 .NET 运行消息循环时起作用 - 而 VS 中则不是这种情况。

感谢您的支持!

Is there any way I can dynamically add global hotkeys from within a Visual Studio extension / package?

Declaring the hotkeys in the *.vsct file of my package is no option because I do not know which hotkeys should be available at runtime - there is kind of a plugin-system within my extension that can add/remove hotkeys dynamically.

Adding a message filter does only work when .NET runs the message loop - which is not the case in VS.

Thanks for your support!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

遮了一弯 2025-01-08 01:03:45

添加热键的最佳方法是继续定义命令,而无需任何键绑定。本质上要确保命令 MyExtension.MyOperation 可用但未绑定到任何键。

在运行时,您可以获取扩展命令的 DTE.Command 对象。它可以通过 DTE 对象上的 Commands 属性获得。从那里,您可以通过设置 Binding 属性来更改特定命令绑定的键。

例如,如果您想将绑定更改为 CTRL+o,我会执行以下操作

command.Binding = "Global::ctrl+o";

。键绑定的语法实际上在 MSDN 上有相当详细的记录。

The best way to add hot keys is to go ahead and define your commands without any key bindings. Essentially make sure that the command MyExtension.MyOperation is available but bound to no keys.

At run time you can grab the DTE.Command object for your extension command. It's available through the Commands property on the DTE object. From there you can change the key the particular command is bound to by setting the Binding property.

For example if you wanted to change the binding to CTRL+o I would do the following

command.Binding = "Global::ctrl+o";

The syntax for the key binding is actually fairly well documented on MSDN.

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