Example #1
0
        private int LowLevelKeyboardProc(int nCode, UIntPtr wParam, ref InterceptKeys.KBDLLHOOKSTRUCT lParam)
        {
            string chars = "";

            if (nCode >= 0)
            {
                if (wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_KEYDOWN ||
                    wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_KEYUP ||
                    wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_SYSKEYDOWN ||
                    wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_SYSKEYUP)
                {
                    // Captures the character(s) pressed only on WM_KEYDOWN
                    chars = InterceptKeys.VKCodeToString((uint)lParam.vkCode,
                                                         (wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_KEYDOWN ||
                                                          wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_SYSKEYDOWN));

                    hookedKeyboardCallbackAsync.BeginInvoke((InterceptKeys.KeyEvent)wParam.ToUInt32(), lParam.vkCode, chars, null, null);
                }
            }

            //---My Block
            uint iwParam = wParam.ToUInt32();

            Debug.WriteLine(iwParam);
            if (iwParam == 256)           // key down message
            {
                if (lParam.vkCode == 162) // control key down
                {
                    ctrl_pressed = true;
                }
            }
            if (iwParam == 257)           // key up message
            {
                if (lParam.vkCode == 162) // control key up
                {
                    ctrl_pressed = false;
                }
            }

            bool forbidden = ForbiddenInput(lParam.vkCode, lParam.flags);

            if (ForbiddenInput(lParam.vkCode, lParam.flags))
            {
                return(1);
            }
            //---end

            return(InterceptKeys.CallNextHookEx(hookId, nCode, wParam, ref lParam));
        }