private IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { // address the messages you are receiving using msg, wParam, lParam if (msg == WM_HOTKEY) { short hkeyid = (short)wParam; if (keyIDs.ContainsKey(hkeyid)) { if (HotKeyPressed != null) { int key = (int)(((int)lParam >> 16) & 0xFFFF); AccessModifierKeys modifier = (AccessModifierKeys)((int)lParam & 0xFFFF); HotKeyPressed(this, new HotKeyEventArgs(modifier, KeyInterop.KeyFromVirtualKey(key))); } } } return(IntPtr.Zero); }
public void RegisterHotKey(AccessModifierKeys modifiers, Key key) { // Generates unique ID string atomName = modifiers.ToString() + key.ToString() + this.GetType().FullName; short hKeyID = GlobalAddAtom(atomName); ModifierKeys = modifiers; if (hKeyID != 0) { if (!RegisterHotKey(Handle, hKeyID, (int)modifiers, KeyInterop.VirtualKeyFromKey(key))) { throw new ArgumentException("Hotkey combination could not be registered."); } else { keyIDs.Add(hKeyID, hKeyID); } } else { throw new ArgumentException("Hotkey ID not generated!"); } }
public HotKeyEventArgs(AccessModifierKeys pModKeys, Key pKey) { ModifierKeys = pModKeys; Key = pKey; }
public void RegisterHotKey(AccessModifierKeys modifiers, Key key) { // Generates unique ID string atomName = modifiers.ToString() + key.ToString() + this.GetType().FullName; short hKeyID = GlobalAddAtom(atomName); ModifierKeys = modifiers; if (hKeyID != 0) { if (!RegisterHotKey(Handle, hKeyID, (int)modifiers, KeyInterop.VirtualKeyFromKey(key))) throw new ArgumentException("Hotkey combination could not be registered."); else keyIDs.Add(hKeyID, hKeyID); } else throw new ArgumentException("Hotkey ID not generated!"); }