Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started 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.
-
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
-
Anyone still interested in such a feature?
-
Sure, we all are.
I'm not sure but I think i asked the same question about 5 years ago :)
Geert
-
It's on Sparx' list of user wishes not to come true in the near future :(
q.
-
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
-
Would you mind to post the link here :)
q.
-
Sure, as soon as it's published after review!
-
lol. Forgot they review the articles before publishing...
q.
-
Cool, I'm curious :)
Geert
-
http://community.sparxsystems.com/community-resources/805-triggering-add-in-functionality-with-custom-hotkeys-in-enterprise-architect
-
Wow, nice article.
I'm definitely going to use that for my add-ins, thanks!
Geert
-
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.
-
Hi Jan,
great!
It's always fascinating how much I can get from this forum. Thanks for all contributers for their great stuff.
Helmut
-
Great feature!
Perfectly meets the need and so easy to implement !
Thank you very much for the time and effort! :D
-
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:
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:
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
-
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
-
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);
}
}
}
}
-
Hi Jan,
thanks a lot.
It works!
Helmut
-
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?