protected override int HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode != 0) { return(HookExtern.CallNextHookEx(this.HookType, nCode, wParam, lParam)); } MouseEventArgs mouseEventArgs = new MouseEventArgs((MouseEventType)wParam, Marshal.PtrToStructure <MouseLLHookStruct>(lParam)); bool isHandled = false; lock (((IList)this.Handlers).SyncRoot) { foreach (HandleMouseInputDelegate handler in this.Handlers) { isHandled = handler(mouseEventArgs); if (isHandled) { break; } } } if (isHandled) { return(1); } else { return(HookExtern.CallNextHookEx(this.HookType, nCode, wParam, lParam)); } }
protected override int HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode != 0) { return(HookExtern.CallNextHookEx(this.HookType, nCode, wParam, lParam)); } KeyboardEventType eventType = (KeyboardEventType)(((uint)wParam % 2) + 256); // filter out SysKeyDown & SysKeyUp Keys key = (Keys)Marshal.ReadInt32(lParam); KeyboardEventArgs KeyboardEventArgs = new KeyboardEventArgs(eventType, key); bool isHandled = false; lock (((IList)this.Handlers).SyncRoot) { foreach (HandleKeyboardInputDelegate handler in this.Handlers) { isHandled = handler(KeyboardEventArgs); if (isHandled) { break; } } } if (isHandled) { return(1); } else { return(HookExtern.CallNextHookEx(this.HookType, nCode, wParam, lParam)); } }