Using system. runtime. interopservices;
/// <Summary>
/// Register hotkeys
/// </Summary>
/// <Param name = "hwnd"> handle to window </param>
/// <Param name = "ID"> Hot Key Identifier </param>
/// <Param name = "fsmodifiers"> key-modifier options </param>
/// <Param name = "VK"> virtual-key code </param>
/// <Returns> </returns>
[Dllimport ("user32.dll", setlasterror = true)]
Public static extern bool registerhotkey (intptr hwnd, int ID, keymodifiers fsmodifiers, keys VK );
/// <Summary>
/// Unregister hotkeys
/// </Summary>
/// <Param name = "hwnd"> handle to window </param>
/// <Param name = "ID"> Hot Key Identifier </param>
/// <Returns> </returns>
[Dllimport ("user32.dll", setlasterror = true)]
Public static extern bool unregisterhotkey (intptr hwnd, int ID );
/// <Summary>
/// Keys for Combination
/// </Summary>
[Flags ()]
Public Enum keymodifiers {
None = 0,
Alt = 1,
Control = 2,
Shift = 4,
Windows = 8
}
/// <Summary>
/// Override the wndproc, when lose focus it can also activate the registered hot keys
/// </Summary>
/// <Param name = "M"> </param>
Protected override void wndproc (ref message m)
{
Const int wm_hotkey = 0x0312; // press the hotkey
Switch (M. msg)
{
Case wm_hotkey:
Callscr ();
Break;
}
Base. wndproc (ref m );
}