Click here to Skip to main content
Licence 
First Posted 11 Jul 2007
Views 16,842
Downloads 93
Bookmarked 25 times

SSMSKeyBindings - edit keybindings in sql mgt studio

By Johan Sassner | 20 Jul 2007
An addin to Sql Server Management studio that lets you configure keybindings
 
Part of The SQL Zone sponsored by
See Also

1

2

3
2 votes, 33.3%
4
4 votes, 66.7%
5
4.67/5 - 6 votes
μ 4.67, σa 0.90 [?]

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Johan Sassner

Web Developer

Sweden Sweden

Member
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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionNot Working on Custom Addin Pinmembermazzanti6:28 27 Jul '11  
QuestionAny changes required to get this to work with SSMS 2008? PinmemberkellyAtWork12:57 30 Dec '08  
QuestionHow to install the add-in and make it work? Pinmemberguaike15:43 22 Jun '08  
AnswerRe: How to install the add-in and make it work? PinmemberJohan Sassner22:27 22 Jun '08  
AnswerRe: How to install the add-in and make it work? PinmemberWhite X Dragon1:10 12 Oct '08  
GeneralGreat! one question PinmemberWin32nipuh20:43 7 Feb '08  
GeneralRe: Great! one question PinmemberJohan Sassner3:33 10 Feb '08  
GeneralThanks for add-in! PinmemberPredrag Tomasevic23:52 27 Nov '07  
GeneralRe: Thanks for add-in! PinmemberJohan Sassner0:40 28 Nov '07  
GeneralThanks! PinmemberChristianMerat6:52 18 Jul '07  

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.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120202.1 | Last Updated 20 Jul 2007
Article Copyright 2007 by Johan Sassner
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid