Click here to Skip to main content
15,867,141 members
Articles / Database Development / SQL Server
Article

SSMSKeyBindings - edit keybindings in sql mgt studio

Rate me:
Please Sign up or sign in to vote.
4.67/5 (6 votes)
20 Jul 2007LGPL32 min read 45.8K   204   25   11
An addin to Sql Server Management studio that lets you configure keybindings

Screenshot - Screenshot.jpg

Introduction

This project is an addin to SQL Server Management Studio 2005 (tested in version 9.00.3042.00 of SSMS; that's SQL 2k5 with SP1 on Vista) for managing keybindings to built in commands (like Copy and Paste), and for other addins that might be registered.

Background

I was writing some other addin, when in some weird way (must be my friend who did this) the Quick Search menu item lost its keybinding. I then wrote a very simple addin that fixed just that command, and then I thought I could improve on this addin to make a keybinding interface similar to Visual Studio 2005.

Using the code

I won't go into the details of creating an addin because there are so many others on codeproject.com that already does it. I will focus on the Command object instead.

What might be interesting is how to retrieve all the existing commands in SSMS, for example <b>Edit.Copy</b> etc. Command objects can be found in the Commands collection of the DTE2 object. To list all commands use:

C#
foreach (Command command in _applicationObject.Commands) {
    Debug.WriteLine(command.Name);
}

To retrieve a special command object use:

C#
Command command = _applicationObject.Commands.Item("Edit.Copy", -1);

When you have a reference to the command object, the keybindings are in the Bindings property. It's an object array with strings on the format of "scopename::modifiers+key".

Scopename can, for example, be Global, SQL Query Editor & View Designer. Modifiers can be Ctrl, Shift & Alt. In the screenshot above you can see that Edit.Copy is bound to Global::Ctrl+C, but it is also bound to Global::Ctrl+Ins which means that you can have several bindings for the same command for different scopes.

These keybindings are stored in a .vsk file in your Document and Settings directory (mine is found in C:\Users\johan.sassner\AppData\Roaming\Microsoft\Microsoft SQL Server\90\Tools\Shell\Current.vsk).

Installation

To use the addin you have to register it using RegAsm (found in your v2.0 framework directory), and then run the included registry file. It adds the following key to the registry:

C#
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\90\Tools\Shell\
    Addins\Sassner.SSMSKeybindings.Connect]
"LoadBehavior"=dword:00000001
"Description"="SSMSKeybindings"
"FriendlyName"="SSMS Keybindings addin,SQL Server Management Studio Extension"

Points of Interest

I did stumble upon a weird bug, which, after a long time, I found a similar reference to a bug in Visual Studio 2003. If you remove the last keybinding on a command, it is not stored in the SSMS settings file. What I had to do was to find another command and just set that command binding object again (no changes, just re-set it).

C#
private void PersistRandomCommand() {
  foreach (Command command in _applicationObject.Commands) {
    if (command.Name.Length > 0) {
      object[] bindings = (object[])command.Bindings;
        if (bindings.Length > 0) {
          command.Bindings = bindings;
          break;
        }
     }
  }
}

History

v1.0 - 2007-07-11, added first version.

v1.01 - 2007-07-11, added how to install the addin.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Web Developer
Sweden Sweden
Working as a developer in the financial business. Been working with computers for 10 years, but have had computers as a hobby for 25 years.

Comments and Discussions

 
QuestionNot Working on Custom Addin Pin
mazzanti27-Jul-11 5:28
mazzanti27-Jul-11 5:28 
QuestionAny changes required to get this to work with SSMS 2008? Pin
kellyAtWork30-Dec-08 11:57
kellyAtWork30-Dec-08 11:57 
It's been beautiful for 2005, but on 2008, It gets error 80004002: No such interface supported.. Does it need to change for 2008, or have I just installed it wrong?
AnswerRe: Any changes required to get this to work with SSMS 2008? Pin
Andrei b>g21-Mar-12 13:33
Andrei b>g21-Mar-12 13:33 
QuestionHow to install the add-in and make it work? Pin
guaike22-Jun-08 14:43
guaike22-Jun-08 14:43 
AnswerRe: How to install the add-in and make it work? Pin
Johan Sassner22-Jun-08 21:27
Johan Sassner22-Jun-08 21:27 
AnswerRe: How to install the add-in and make it work? Pin
White X Dragon12-Oct-08 0:10
White X Dragon12-Oct-08 0:10 
GeneralGreat! one question Pin
Win32nipuh7-Feb-08 19:43
professionalWin32nipuh7-Feb-08 19:43 
GeneralRe: Great! one question Pin
Johan Sassner10-Feb-08 2:33
Johan Sassner10-Feb-08 2:33 
GeneralThanks for add-in! Pin
lepipele27-Nov-07 22:52
lepipele27-Nov-07 22:52 
GeneralRe: Thanks for add-in! Pin
Johan Sassner27-Nov-07 23:40
Johan Sassner27-Nov-07 23:40 
GeneralThanks! Pin
ChristianMerat18-Jul-07 5:52
ChristianMerat18-Jul-07 5:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.