예제 #1
0
        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));
            }
        }
예제 #2
0
        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));
            }
        }
예제 #3
0
        public virtual void DisableHook()
        {
            if (hook == IntPtr.Zero)
            {
                return;
            }

            Logger.Debug("Disabling");

            HookExtern.UnhookWindowsHookEx(hook);
            hook = IntPtr.Zero;
        }
예제 #4
0
        public virtual bool EnableHook()
        {
            if (hook != IntPtr.Zero)
            {
                return(true);
            }

            Logger.Debug("Enabling");

            hook = HookExtern.SetWindowsHookEx(this.HookType, hookProc, IntPtr.Zero, 0);
            return(hook != IntPtr.Zero);
        }