CallNextHookEx() private method

private CallNextHookEx ( HOOK hhk, HC nCode, WM wParam, IntPtr lParam ) : int
hhk HOOK
nCode HC
wParam WM
lParam System.IntPtr
return int
示例#1
0
        private static int OnKey(HC nCode, WM wParam, IntPtr lParam)
        {
            bool is_key = (wParam == WM.KEYDOWN || wParam == WM.SYSKEYDOWN ||
                           wParam == WM.KEYUP || wParam == WM.SYSKEYUP);

            if (m_duplicate != 0)
            {
                // Do nothing. We can only get here if a key is pressed during
                // the very short time where we have two hooks installed, i.e.
                // practically never, but it’s better to handle this properly.
            }
            else if (nCode == HC.ACTION && is_key)
            {
                // Retrieve key event data from native structure
                var data = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam,
                                                                   typeof(KBDLLHOOKSTRUCT));
                bool is_injected = (data.flags & LLKHF.INJECTED) != 0;
                bool accept      = !is_injected || (Settings.AllowInjected.Value && m_recursive == 0);

                Logger.Debug("{0}{1}: OnKey(HC.{2}, WM.{3}, [vk:0x{4:X02} ({7}) sc:0x{5:X02} flags:{6}])",
                             accept ? "" : "Ignored ", is_injected ? "Injected Event" : "Event",
                             nCode, wParam, (int)data.vk, (int)data.sc, data.flags, new Key(data.vk));

                if (accept)
                {
                    ++m_recursive;
                    bool processed = Composer.OnKey(wParam, data.vk, data.sc, data.flags);
                    --m_recursive;

                    if (processed)
                    {
                        return(-1); // Do not process further: that key was for us.
                    }
                }
            }
            else
            {
                Logger.Debug("Ignored Event: OnKey({0}, {1})", nCode, wParam);
            }

            // Call next hook but guard against re-doing our own work in case we
            // were installed twice.
            ++m_duplicate;
            int ret = NativeMethods.CallNextHookEx(m_hook, nCode, wParam, lParam);

            --m_duplicate;

            return(ret);
        }
示例#2
0
        private static int OnKey(HC nCode, WM wParam, IntPtr lParam)
        {
            if (nCode == HC.ACTION)
            {
                // Retrieve event data from native structure
                var data = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam,
                                                                   typeof(KBDLLHOOKSTRUCT));

                bool is_key = (wParam == WM.KEYDOWN || wParam == WM.SYSKEYDOWN ||
                               wParam == WM.KEYUP || wParam == WM.SYSKEYUP);
                bool is_injected = (data.flags & LLKHF.INJECTED) != 0;

                if (is_key && !is_injected)
                {
                    if (Composer.OnKey(wParam, data.vk, data.sc, data.flags))
                    {
                        // Do not process further: that key was for us.
                        return(-1);
                    }
                }
            }

            return(NativeMethods.CallNextHookEx(m_hook, nCode, wParam, lParam));
        }