Example #1
0
    private bool IsHooked(KBDLLHOOKSTRUCT lParam)
    {
        if ((lParam.vkCode == VirtualKeys.VK_ESCAPE) && GetModifierKeyPressed(ModifierKeys.Control))
        {
            Debug.WriteLine("Ctrl + Esc");
            return((_BlockType & KeyboardBlockType.CtrlAndEsc) == KeyboardBlockType.CtrlAndEsc);
        }
        if ((lParam.vkCode == VirtualKeys.VK_TAB) && ((lParam.flags & LLKHF_ALTDOWN) == LLKHF_ALTDOWN))
        {
            Debug.WriteLine("Alt + Tab");
            return((_BlockType & KeyboardBlockType.AltAndTab) == KeyboardBlockType.AltAndTab);
        }
        if ((lParam.vkCode == VirtualKeys.VK_ESCAPE) && ((lParam.flags & LLKHF_ALTDOWN) == LLKHF_ALTDOWN))
        {
            Debug.WriteLine("Alt + Esc");
            return((_BlockType & KeyboardBlockType.AltAndEsc) == KeyboardBlockType.AltAndEsc);
        }
        if (CLang.In(lParam.vkCode, VirtualKeys.VK_LWIN, VirtualKeys.VK_RWIN))
        {
            Debug.WriteLine("Window Key");
            return((_BlockType & KeyboardBlockType.WindowKey) == KeyboardBlockType.WindowKey);
        }

        Debug.WriteLine("false");
        return(false);
    }
Example #2
0
    /// <summary>
    /// Processes the key event captured by the hook.
    /// </summary>
    private IntPtr HookCallback(int nCode, IntPtr wParam, ref KBDLLHOOKSTRUCT lParam)
    {
        if (nCode == HC_ACTION)
        {
            if (CLang.In(wParam, (IntPtr)WM_KEYDOWN, (IntPtr)WM_KEYUP, (IntPtr)WM_SYSKEYDOWN, (IntPtr)WM_SYSKEYUP))
            {
                if (IsHooked(lParam))
                {
                    //OnKeyIntercepted(new KeyboardHookEventArgs(lParam.vkCode, AllowKey));

                    return((System.IntPtr) 1);
                }
            }
        }
        //Pass key to next application
        return(NativeMethods.CallNextHookEx(hookID, nCode, wParam, ref lParam));
    }