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