示例#1
0
            private IntPtr LowLevelMouseEvent(int nCode, IntPtr wParam, IntPtr lParam)
            {
                bool fEatMouseEvent = false;

                var wparamTyped = wParam.ToInt32();

                if (Enum.IsDefined(typeof(MouseMessages), wparamTyped))
                {
                    object         o = Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
                    MSLLHOOKSTRUCT p = (MSLLHOOKSTRUCT)o;

                    var eventArguments = new GlobalMouseHookEventArgs((MouseMessages)wparamTyped, p);

                    EventHandler <GlobalMouseHookEventArgs> handler = MouseEvent;
                    handler?.Invoke(this, eventArguments);

                    fEatMouseEvent = eventArguments.Handled;
                }

                return(fEatMouseEvent ? (IntPtr)(-1) : DLLImports.CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam));
            }
示例#2
0
            public IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam)
            {
                bool fEatKeyStroke = false;

                var wparamTyped = wParam.ToInt32();

                if (Enum.IsDefined(typeof(KeyboardState), wparamTyped))
                {
                    object o = Marshal.PtrToStructure(lParam, typeof(LowLevelKeyboardInputEvent));
                    LowLevelKeyboardInputEvent p = (LowLevelKeyboardInputEvent)o;

                    var eventArguments = new GlobalKeyboardHookEventArgs(p, (KeyboardState)wparamTyped);

                    EventHandler <GlobalKeyboardHookEventArgs> handler = KeyboardPressed;
                    handler?.Invoke(this, eventArguments);

                    fEatKeyStroke = eventArguments.Handled;
                }

                return(fEatKeyStroke ? (IntPtr)(-1) : DLLImports.CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam));
            }