使用宏在 Visual Studio 中删除键盘快捷键绑定

发布于 2024-08-22 17:19:52 字数 520 浏览 11 评论 0原文

我设置了很多自定义键盘快捷键。为了避免每次安装新的 Visual Studio 时都必须设置它们(这种情况经常发生,VS2010 处于 beta/RC 版本),我创建了一个宏,用于设置所有自定义命令,如下所示:

DTE.Commands.Item("ReSharper.ReSharper_UnitTest_RunSolution").Bindings = "Global::Ctrl+T, Ctrl+A"

我的主要问题是 Ctrl+T 默认设置为映射到转置 char 命令。所以我想删除宏中的默认值。

我尝试了以下两行,但都抛出异常

DTE.Commands.Item("Edit.CharTranspose").Bindings = ""
DTE.Commands.Item("Edit.CharTranspose").Bindings = Nothing

虽然它们有点工作,因为它们实际上删除了绑定;)但我更喜欢不抛出异常的解决方案。

这是怎么做到的?

I have a lot of custom keyboard shortcuts set up. To avoid having to set them up every time I install a new visual studio (happens quite a lot currectly, with VS2010 being in beta/RC) I have created a macro, that sets up all my custom commands, like this:

DTE.Commands.Item("ReSharper.ReSharper_UnitTest_RunSolution").Bindings = "Global::Ctrl+T, Ctrl+A"

My main problem is that Ctrl+T is set up to map to the transpose char command by default. So I want to remove that default value in my macro.

I have tried the following two lines, but both throw an exception

DTE.Commands.Item("Edit.CharTranspose").Bindings = ""
DTE.Commands.Item("Edit.CharTranspose").Bindings = Nothing

Although they kind of work, because they actually remove the binding ;) But I would prefer the solution that doesn't throw an exception.

How is that done?

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

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

发布评论

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

评论(3

ぃ弥猫深巷。 2024-08-29 17:19:52

我已经处理过同样的问题。我使用宏为一组对齐宏分配键绑定。

Dim NewBindings() = {"Global::Alt+="}
DTE.Commands.Item("Macros.Dev.AlignUtils.AlignEquals").Bindings = NewBindings
NewBindings(0) = "Global::Alt+Num -"
DTE.Commands.Item("Macros.Dev.AlignUtils.AlignMinus").Bindings = NewBindings
...

为了删除键绑定,我使用以下语句:

Dim DelBindings() = {} 
DTE.Commands.Item("Macros.Dev.AlignUtils.AlignPlus").Bindings = DelBindings

它在 Visual Studio 2005 下工作正常。

I have coped with the same issue. I use a macro to assign key bindings for a set of align macros.

Dim NewBindings() = {"Global::Alt+="}
DTE.Commands.Item("Macros.Dev.AlignUtils.AlignEquals").Bindings = NewBindings
NewBindings(0) = "Global::Alt+Num -"
DTE.Commands.Item("Macros.Dev.AlignUtils.AlignMinus").Bindings = NewBindings
...

And to remove key bindings i use the following statements :

Dim DelBindings() = {} 
DTE.Commands.Item("Macros.Dev.AlignUtils.AlignPlus").Bindings = DelBindings

It works fine under Visual Studio 2005.

遇到 2024-08-29 17:19:52

我遵循了一种更务实的方式(使用您的示例):

DTE.Commands.Item("ReSharper.ReSharper_UnitTest_RunSolution").Bindings = "Global::Ctrl+T"
DTE.Commands.Item("ReSharper.ReSharper_UnitTest_RunSolution").Bindings = "Global::Ctrl+T, Ctrl+A"

在第一个分配中,Ctrl+T 未从任何其他函数分配,然后与第二个分配解除绑定。

对我来说就像一个魅力。

I followed a little more pragmatic way (using your example):

DTE.Commands.Item("ReSharper.ReSharper_UnitTest_RunSolution").Bindings = "Global::Ctrl+T"
DTE.Commands.Item("ReSharper.ReSharper_UnitTest_RunSolution").Bindings = "Global::Ctrl+T, Ctrl+A"

With the first assignment Ctrl+T is unassigned from any other function and then becomes unbound with the second assignment.

Works like a charm for me.

箹锭⒈辈孓 2024-08-29 17:19:52

您不需要使用宏来更改它,只需进入

菜单>工具>选项--键盘,然后从下拉列表中选择您想要更改的快捷方式并分配您想要的快捷方式

You do not need to change it with macro, Just go to

Menu>Tools>Options -- Keyboard and then select what you want to change the shortcut from the dropdown and assignyour desiered short cut

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