Version 2.7
Copyright © 2007, 2008, 2009, 2010, 2011, 2012 vogella GmbH
17.01.2012
Table of Contents
This tutorial describes the Eclipse 3.x API which is used for Eclipse IDE plug-in development.
For Eclipse RCP you should use the new Eclipse 4 API which is described in the Eclipse RCP tutorial.
Via key bindings you can define shortcuts for your Eclipse Commands.
Eclipse uses a default key configuration scheme. If your application uses existing plug-ins where key bindings are already defined these key bindings will also be active in your Eclipse RCP application. If that is not desired then you can configure your product to use another scheme.
The following describes first how to create key bindings using this default configuration scheme. Afterwards I how to overwrite the default key binding scheme of Eclipse.
To define a shortcut for a command you use
org.eclipse.ui.bindings
extension point
together with the
org.eclipse.ui.defaultAcceleratorConfiguration
schemeId
and the
org.eclipse.ui.contexts.window
contextId.
To define and use your own scheme you need:
Define a new scheme via extension point "org.eclipse.ui.bindings"
Assign this scheme to the key bindings you defined
Have a product created
Define the file "plugin_customization.ini" and set the scheme for the product via a property.
This tutorial assumes that you have basic understanding of development for the Eclipse platform. Please see Eclipse RCP Tutorial or Eclipse Plug-in Tutorial if you need any basic information.
The following also assumes that you are familiar with Eclipse Commands. To learn about them you can use the For an introduction please see the Eclipse Commands Tutorial and the Eclipse Advanced Commands Tutorial which contain a introduction into the material.
Create a new project "de.vogella.rcp.intro.commands.keybinding" using the "Hello RCP" template, declare command "de.vogella.rcp.intro.commands.keybinding.hello" with a default handler "de.vogella.rcp.intro.commands.keybinding.HelloHandler" which prints out "Hello" to the console
Add the extension point "org.eclipse.ui.bindings" to your project. Right-click in this extension point, select New-> Key.
Select as schemeID "org.eclipse.ui.defaultAcceleratorConfiguration" this is the workbench default and will make sure you keybinding is valid in the whole application. The commandId is the ID of the command you just created. The sequence is the shortcut key for calling the command. M1 represents the Ctrl key.

If you now run it the keybinding should work and if you press Ctrll+1 the message on the console should be visible.
Add now another key binding "Ctrl+N" to the command "de.vogella.rcp.intro.commands.keybinding.hello". Try it. This will not work as it is conflicting with the Eclipse default schema.
Right-click in this extension point "org.eclipse.ui.bindings", select New-> Scheme. Create a schema with the id "MyScheme".

Assign the scheme id to your commands.

Define a product. See Defining a product for Eclipse RCP for details. Create the following file "plugin_customization.ini" and put it in your main directory
org.eclipse.ui/KEY_CONFIGURATION_ID=myscheme

If you now run your product the "Ctrl+N" shortcut should work.
Please consider a contribution
if this article helped you. It will help to maintain our content and our Open Source activities.
Writing and updating these tutorials is a lot of work. If this free community service was helpful, you can support the cause by giving a tip as well as reporting typos and factual errors.
If you find errors in this tutorial, please notify me (see the top of the page). Please note that due to the high volume of feedback I receive, I cannot answer questions to your implementation. Ensure you have read the vogella FAQ as I don't respond to questions already answered there.
This tutorial is Open Content under the CC BY-NC-SA 3.0 DE license. Source code in this tutorial is distributed under the Eclipse Public License. See the vogella License page for details on the terms of reuse.
| TRAINING | SERVICE & SUPPORT |
|---|---|
| The vogella company provides comprehensive training and education services from experts in the areas of Eclipse RCP, Android, Git, Java, Gradle and Spring. We offer both public and inhouse training. Whichever course you decide to take, you are guaranteed to experience what many before you refer to as “The best IT class I have ever attended”. | The vogella company offers expert consulting services, development support and coaching. Our customers range from Fortune 100 corporations to individual developers. |