4

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?

Pete
  • 12,206
  • 8
  • 54
  • 70

3 Answers3

3

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.

Arno
  • 46
  • 3
2

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.

Pascal
  • 2,197
  • 3
  • 24
  • 34
  • This does have an interesting benefit compared to the original solution - you don't actually have to know what the key was originally bound to. – Pete Nov 11 '13 at 14:49
-2

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

Nasser Hadjloo
  • 12,312
  • 15
  • 69
  • 100
  • I read it and completely underestand what you want to do. but I never found a solutionfor thatWhen I wanted to do someting like you. **note** that VS replace newver shortcut with previous ones . so if you are creating a new short cut it will override the previous one and the previous one take a new short cut. and you can not find a way to getinformation about new keys whichgenerated for old one. you just can change the old one with the wayI mentioned if you want to stay informed about old ones. – Nasser Hadjloo Feb 24 '10 at 09:04
  • 2
    Well, if you read the question, you certainly did not understand it. My entire point is that i want to avoid going to the options menu, when every other option is set by a macro. – Pete Feb 24 '10 at 10:21
  • 1
    ok, then, -1 for not understanding that an answer should be at least somewhat relevant to the question. wtf. – Sky Sanders Feb 24 '10 at 19:58