Code Using System;
Using System. Runtime. InteropServices;
Namespace SystemHotKey
{
Public delegate void HotkeyEventHandler (int HotKeyID );
Public class Hotkey: System. Windows. Forms. IMessageFilter
{
System. Collections. Hashtable keyIDs = new System. Collections. Hashtable ();
IntPtr hWnd;
Public event HotkeyEventHandler OnHotkey;
Public enum KeyFlags
{
MOD_ALT = 0x1,
MOD_CONTROL = 0x2,
MOD_SHIFT = 0x4,
MOD_WIN = 0x8
}
[DllImport ("user32.dll")]
Public static extern UInt32 uregisterhotkey (IntPtr hWnd, UInt32 id, UInt32 fsModifiers, UInt32 vk );
[DllImport ("user32.dll")]
Public static extern UInt32 uunregisterhotkey (IntPtr hWnd, UInt32 id );
[DllImport ("kernel32.dll")]
Public static extern UInt32 GlobalAddAtom (String lpString );
[DllImport ("kernel32.dll")]
Public static extern UInt32 uglobaldeleteatom (UInt32 nAtom );
Public Hotkey (IntPtr hWnd)
{
This. hWnd = hWnd;
System. Windows. Forms. Application. AddMessageFilter (this );
}
Public int RegisterHotkey (System. Windows. Forms. Keys Key, KeyFlags