You need to subscribe to certain messages that the operating system sends by means of a native function call like RegisterHotKey()
. When you call this function You tell the operating system which window to send the messages to by specifying the Handle
of the window, this can be considered an address. When you set ShowInTaskbar = false
the handle changes so the operating system will not know where to reach you.
See the first arugment:
RegisterHotKey(this.Handle, MYACTION_HOTKEY_ID, 0, (int) Keys.F9);
To resolve your issue you can create a class that derives from NativeWindow
which "Provides a low-level encapsulation of a window handle and a window procedure." and from within that class (or at least using that class's handle depending on your implementation), register the hotkeys using a handle that will never change.
public sealed class HotkeyManager : NativeWindow, IDisposable
{
public HotkeyManager()
{
CreateHandle(new CreateParams());
}
protected override void WndProc(ref Message m)
{
if (m.Msg == Constants.WM_HOTKEY)
{
//handle hotkey message
}
base.WndProc(ref m);
}
public void Dispose()
{
DestroyHandle();
}
}