
Subscribe
0 Comments
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.
The logic behind this workaround is summarised as follows:
The workaround uses several classes to provide the keyboard shortcut functionality:
The following class diagram illustrates the design of the example:
Main
Description
This class provides the entry point to all EA Extensions and is where the developer will define:
In this example, there are four menu options which provide very basic functionality:
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.
Code
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.
MenuManager
Description
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).
Code
AboutBox
Description
For the purposes of this example, the class is the standard class that is provided by the C# .NET framework.
HotKeyForm
Description
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.
Code
KeyBoardHook
Description
This class provides all the “wiring” between the registered keyboard shortcuts, and the keypressed event.
Code
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:
Please note that this example was built using Visual Studio 2017 and the .NET framework version 4.6.1
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.
Cookie | Duration | Description |
---|---|---|
cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |