Click here to Skip to main content
Click here to Skip to main content
Go to top

SSMSKeyBindings - edit keybindings in sql mgt studio

, 20 Jul 2007
Rate this:
Please Sign up or sign in to vote.
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:

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

To retrieve a special command object use:

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:

[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).

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)

Share

About the Author

Johan Sassner
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 Pinmembermazzanti27-Jul-11 5:28 
QuestionAny changes required to get this to work with SSMS 2008? PinmemberkellyAtWork30-Dec-08 11:57 
AnswerRe: Any changes required to get this to work with SSMS 2008? PinmemberAndrei Rantsevich21-Mar-12 13:33 
QuestionHow to install the add-in and make it work? Pinmemberguaike22-Jun-08 14:43 
AnswerRe: How to install the add-in and make it work? PinmemberJohan Sassner22-Jun-08 21:27 
AnswerRe: How to install the add-in and make it work? PinmemberWhite X Dragon12-Oct-08 0:10 
GeneralGreat! one question PinmemberWin32nipuh7-Feb-08 19:43 
GeneralRe: Great! one question PinmemberJohan Sassner10-Feb-08 2:33 
GeneralThanks for add-in! PinmemberPredrag Tomasevic27-Nov-07 22:52 
GeneralRe: Thanks for add-in! PinmemberJohan Sassner27-Nov-07 23:40 
GeneralThanks! PinmemberChristianMerat18-Jul-07 5:52 
Thank you very much! Finally a way to map a hotkey to Find in Files!

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 20 Jul 2007
Article Copyright 2007 by Johan Sassner
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid