Beispiel #1
0
        public virtual void Subscribe()
        {
            if (_hooksHandle != 0)
            {
                return;
            }

            lock (_padLock)
            {
                // install Mouse hook only if it is not installed and must be installed
                if (_hooksHandle == 0)
                {
                    _hooksProc = HooksProc;

                    //install hook
                    _hooksHandle = ChoUser32.SetWindowsHookEx(
                        (int)_hookType,
                        _hooksProc, IntPtr.Zero,
                        //Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]),
                        0);
                    //If SetWindowsHookEx fails.
                    if (_hooksHandle == 0)
                    {
                        ChoWin32Exception.CheckNThrowException();
                    }
                }
            }
        }
Beispiel #2
0
        public virtual void Unsubscribe()
        {
            if (_hooksHandle == 0)
            {
                return;
            }

            lock (_padLock)
            {
                // install Mouse hook only if it is not installed and must be installed
                if (_hooksHandle != 0)
                {
                    //install hook
                    int result = ChoUser32.UnhookWindowsHookEx(_hooksHandle);
                    _hooksHandle = 0;
                    //If SetWindowsHookEx fails.
                    if (result == 0)
                    {
                        ChoWin32Exception.CheckNThrowException();
                    }
                }
            }
        }