Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Tehila1 on January 12, 2014, 06:42:56 pm

Title: EA Addin Key Shortcut
Post by: Tehila1 on January 12, 2014, 06:42:56 pm
I would like to enable the add-in to be invoked in the most convenient way.
How can I define a key shortcut in EA for this purpose?
Thanks.
Title: Re: EA Addin Key Shortcut
Post by: Helmut Ortmann on January 13, 2014, 07:12:47 am
Hello,

as far as I know there is no way to define a shortcut for an Addin.

What you can do is: Make an Addin which uses the AddinWindow. Then you are only one click away from your Addin action.

To do this is to make your Addin an ActiveX Control (OCX). Geerts Navigator is a good example.

Helmut


Title: Re: EA Addin Key Shortcut
Post by: McMannus on April 16, 2014, 08:43:36 am
Anyone still interested in such a feature?
Title: Re: EA Addin Key Shortcut
Post by: Geert Bellekens on April 16, 2014, 04:55:43 pm
Sure, we all are.

I'm not sure but I think i asked the same question about 5 years ago :)

Geert
Title: Re: EA Addin Key Shortcut
Post by: qwerty on April 16, 2014, 07:07:42 pm
It's on Sparx' list of user wishes not to come true in the near future  :(

q.
Title: Re: EA Addin Key Shortcut
Post by: McMannus on May 16, 2014, 03:59:03 am
Hi guys,

I've just submitted an extensive tutorial on how this task can be achieved for review to the Community Site =) I hope you'll benefit from it!

Jan
Title: Re: EA Addin Key Shortcut
Post by: qwerty on May 16, 2014, 05:06:43 am
Would you mind to post the link here  :)

q.
Title: Re: EA Addin Key Shortcut
Post by: McMannus on May 16, 2014, 05:11:28 am
Sure, as soon as it's published after review!
Title: Re: EA Addin Key Shortcut
Post by: qwerty on May 16, 2014, 06:48:25 am
lol. Forgot they review the articles before publishing...

q.
Title: Re: EA Addin Key Shortcut
Post by: Geert Bellekens on May 16, 2014, 03:26:04 pm
Cool, I'm curious  :)

Geert
Title: Re: EA Addin Key Shortcut
Post by: McMannus on May 19, 2014, 05:16:20 pm
http://community.sparxsystems.com/community-resources/805-triggering-add-in-functionality-with-custom-hotkeys-in-enterprise-architect
Title: Re: EA Addin Key Shortcut
Post by: Geert Bellekens on May 19, 2014, 06:07:31 pm
Wow, nice article.
I'm definitely going to use that for my add-ins, thanks!

Geert
Title: Re: EA Addin Key Shortcut
Post by: qwerty on May 19, 2014, 06:15:31 pm
Excellent. Though I'm not developing in those depths of Windoze the description is elaborated thoroughly and in a way that you can follow. I wonder why Sparx is still not able to provide that in a plain API method :(

q.
Title: Re: EA Addin Key Shortcut
Post by: Helmut Ortmann on May 20, 2014, 05:46:38 am
Hi Jan,

great!

It's always fascinating how much I can get from this forum. Thanks for all contributers for their great stuff.

Helmut
Title: Re: EA Addin Key Shortcut
Post by: Tehila1 on May 26, 2014, 07:20:43 pm
Great feature!

Perfectly meets the need and so easy to implement !

Thank you very much for the time and effort!  :D
Title: Re: EA Addin Key Shortcut
Post by: McMannus on August 07, 2014, 02:30:12 am
Hi guys,

just to keep you informed about a significant improvement that I discovered during searching the documentation:

The approach for figuring out the currently active application was solved by the background worker thread running infinitely. In the field, this caused ~50% CPU occupation during idle time.

The idea is to solve that by reacting to window events.

Just replace the WndProc method in InvisibleHotkeyForm class with the following code:

Code: [Select]
       protected override void WndProc(ref Message m)
        {
            if (m.Msg == Hotkey.WM_HOTKEY_MSG_ID)
            {
                foreach (Hotkey key in _hotkeys)
                {
                    if (key.IsPressedKeyCombination(m.LParam))
                    {
                        key.Handler();
                        break;
                    }
                }
            }
            else if (m.Msg == WM_ACTIVATEAPP || m.Msg == WM_NCACTIVATE)
            {
                bool windowGotFocus = (m.WParam.ToInt32() == 1);
                if (windowGotFocus)
                {
                    RegisterHotKeys();
                }
                else
                {
                    UnregisterHotKeys();
                }
            }
            base.WndProc(ref m);
        }

and at these two constants to the class:
Code: [Select]
       private const int WM_ACTIVATEAPP = 0x001C;
        private const int WM_NCACTIVATE = 0x0086;

Afterwards the ActiveProcess.cs can be deleted as well as all things that are related to the background worker.

In addition, remove the RegisterHotkeys() call from the OnLoad method.

Regards,
Jan
Title: Re: EA Addin Key Shortcut
Post by: Helmut Ortmann on August 07, 2014, 03:37:45 am
Hi Jan,

thanks a lot.

Could you explain what you mean by 'as well as all things that are related to the background worker'?

Thanks,

Helmut
Title: Re: EA Addin Key Shortcut
Post by: McMannus on August 07, 2014, 05:15:43 am
Code: [Select]
public partial class InvisibleHotKeyForm : Form
    {
        private const int WM_ACTIVATEAPP = 0x001C;
        private const int WM_NCACTIVATE = 0x0086;

        private readonly IEnumerable<Hotkey> _hotkeys;
        private readonly IDualRepository _rep;

        public InvisibleHotKeyForm(IEnumerable<Hotkey> hotkeys, IDualRepository rep)
        {
            InitializeComponent();
            _hotkeys = hotkeys;
            _rep = rep;
            Closing += (sender, eventArgs) => ((List<Hotkey>) _hotkeys).ForEach(key => key.Dispose());
        }

        protected override void OnLoad(EventArgs e)
        {
            Visible = false;
            ShowInTaskbar = false;
            base.OnLoad(e);
        }

        protected override void WndProc(ref Message m)
        {
            if (m.Msg == Hotkey.WM_HOTKEY_MSG_ID)
            {
                foreach (Hotkey key in _hotkeys)
                {
                    if (key.IsPressedKeyCombination(m.LParam))
                    {
                        key.Handler();
                        break;
                    }
                }
            }
            else if (m.Msg == WM_ACTIVATEAPP || m.Msg == WM_NCACTIVATE)
            {
                bool windowGotFocus = (m.WParam.ToInt32() == 1);
                if (windowGotFocus)
                {
                    RegisterHotKeys();
                }
                else
                {
                    UnregisterHotKeys();
                }
            }
            base.WndProc(ref m);
        }

        private void UnregisterHotKeys()
        {
            if (!_hotkeys.Any()) return;
            foreach (Hotkey key in _hotkeys)
            {
                key.Unregister();
            }
        }

        private void RegisterHotKeys()
        {
            UnregisterHotKeys();
            foreach (Hotkey key in _hotkeys)
            {
                try
                {
                    key.Register(window: this);
                }
                catch (GlobalHotkeyException exc)
                {
                    Debug.WriteLine(exc.Message);
                }
            }
        }
    }
Title: Re: EA Addin Key Shortcut
Post by: Helmut Ortmann on August 09, 2014, 06:43:41 pm
Hi Jan,

thanks a lot.

It works!

Helmut
Title: Re: EA Addin Key Shortcut
Post by: avanzwol on July 09, 2025, 10:16:19 pm
http://community.sparxsystems.com/community-resources/805-triggering-add-in-functionality-with-custom-hotkeys-in-enterprise-architect
The URL gives a 404 error.  :-[ Does anyone still have this info somewhere?