Print this page
Thursday, 12 July 2018 09:54

Using Keyboard Shortcuts with Enterprise Architect Extension Menus

Written by
Rate this item
(9 votes)

Using Keyboard Shortcuts with Enterprise Architect Extension MenusUsing Keyboard Shortcuts with Enterprise Architect Extension Menus

by Phil Chudley, Principal Consultant at Dunstan Thomas Consulting


Extensions written for Enterprise Architect often define menus to invoke functionality, and although a short cut of the form Alt+character can be defined by prefixing the character in the menu option with &, this does not work as a keyboard shortcut.

After digging around a bit, I have discovered a work-around so that defined keyboard shortcuts can invoke menu options.

In this article I will explain through a simple example how to use this work-around in your EA Extension. This example has been tested on EA version 13.5 and EA version 14.

Plan of Attack

The logic behind this workaround is summarised as follows:

  • Encapsulate all functionality that is invoked from the menu options in a Manager class, with public methods. This allows the functionality to be invoked from the menu and from the keyboard shortcut.
  • Define your keyboard shortcut, ideally selecting combinations that are not already in use by EA. These are of the form of:
    • Modifier(s) + key – for example Alt+1 or Ctrl+Alt+D
  • All these keyboard shortcuts are registered with a keyboard Hook class associated with a Windows Form class.
  • A key pressed event handler is added to the keyboard Hook class.
  • The Windows Form class is never displayed, but catches the key pressed event. The event can be tested against the keyboard shortcut keys that have been registered and the corresponding menu function invoked using the Menu Manager class.

Overview of the Classes Defined in the Example

The workaround uses several classes to provide the keyboard shortcut functionality:

  • Main – the central class that is always required for all EA Extensions
  • MenuManager – a C# class that provides the functionality for all menu options
  • AboutBox – a standard Windows AboutBox Form class
  • HotKeyForm – a Windows Form class defining an empty window, which is never displayed, but whose sole purpose is to catch the keyboard event raised when pressing the keyboard shortkey combination, and to invoke the Extension’s menu functionality.
  • KeyBoardHook – a C# class which registers the keyboard shortcuts, and raises the keyboard event when the keyboard shortcut keys are pressed.
  • KeyPressedEventArgs – a C# class that encapsulates the event after the keyboard shortcut keys have been pressed. (Defined within KeyBoardHook)

The following class diagram illustrates the design of the example:

Using Keyboard Shortcuts with Enterprise Architect Extension Menus - UML Class Diagram

Detail & Code of the Classes



This class provides the entry point to all EA Extensions and is where the developer will define:

  • Menu text for the extensions menus
  • Global references to other classes, including EA.Repository
  • Handle the appropriate EA broadcast events for;
    • the initial connection to the Extension made by EA
    • the menu contents
    • menu enable / disable check / uncheck
    • menu click
    • EA disconnecting from the Extension
  • Helper methods to provide functionality such as if a model repository is loaded.
  • Code to handle any events broadcast by EA.

In this example, there are four menu options which provide very basic functionality:

  • Option 1 – displays a Message Box
  • Option 2 – displays a Message Box
  • Option 3 – displays a Message Box
  • About – displays the About Box

This functionality is available whether or not a model repository has been loaded and can be invoked via the menu, or by pressing the defined keyboard shortcut key combination.


Using Keyboard Shortcuts with Enterprise Architect Extension Menus

In the method EA_Connect, the instantiation of HotKeyForm, registers the keyboard shortcuts and creates the form, its event and listener. An instantiation of the MenuManager class is also created.



This class defines a public method for each menu option so that these can be invoked from the class Main (as shown above), and also from with the HotKeyForm (shown later).


Using Keyboard Shortcuts with Enterprise Architect Extension Menus



For the purposes of this example, the class is the standard class that is provided by the C# .NET framework.



This class is a Windows Form class and instantiates an instance of the KeyBoardHook class, adds an EventHandler for the KeyPressedEvent and registers each keyboard shortcut key combination with the KeyBoardHook instance.




This class provides all the “wiring” between the registered keyboard shortcuts, and the keypressed event.


Does it Work?

Absolutely! The only way to see that it works is to create the Extension and try it out. This could be achieved by adding the code above to you own extension, or using the attached zip file which contains:

  • Visual Studio solution for classes used in the example
  • MSI installer for the example

Please note that this example was built using Visual Studio 2017 and the .NET framework version 4.6.1

Next Steps

This simple example assumes all Extension menu options are enabled all of the time, I am working on a variation of this example to provide keyboard shortcuts which are active only if a menu option is enabled or checked, and not active when a menu option is disabled or unchecked.

I hope this example is useful to all those of you who develop extensions for EA and I welcome your feedback.

Follow me on Twitter @SparxEAGuru

Read 4575 times Last modified on Monday, 16 July 2018 06:17

Phil Chudley

Dunstan Thomas (Principal Consultant)
I am a Principal Consultant at Dunstan Thomas Consultancy Ltd, Portsmouth, UK. I have been using Enterprise Architect for the last 14 years, and UML even longer than that! I also provide training and consultancy services for organisations using Enterprise Architect.
My main modelling interests are UML, BPMN 2.0, SysML 1.5 and Archimate 3.0 and I am both UML and TOGAF 9.0 certified.
I write extensions for Enterprise Architect especially custom modelling environments using MDG.
I am also an active member of the EAUG and have presented all the London events in addition to Nuremberg, Munich, Zurich, Brussels and Gothenburg.
follow me on Twitter

Latest from philchudley

1 comment

Login to post comments