Example #1
0
    private static IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam)
    {
        bool blnEat = false;

        Dbg.Inf("LLKPA");

        try
        {
            var o = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));

            Dbg.Inf("LLKP");
            switch (wParam.ToInt64())
            {
            case 256:
            case 257:
            case 260:
            case 261:

                //Alt+Tab, Alt+Esc, Ctrl+Esc, Windows Key,
                blnEat = ((o.vkCode == 9) && (o.flags == 32))    // alt+tab
                         | ((o.vkCode == 27) && (o.flags == 32)) // alt+esc
                         | ((o.vkCode == 27) && (o.flags == 0))  // ctrl+esc
                         | ((o.vkCode == 91) && (o.flags == 1))  // left winkey
                         | ((o.vkCode == 92) && (o.flags == 1))
                         | ((o.vkCode == 73) && (o.flags == 0));

                break;
            }
        }
        catch (Exception ex)
        {
            Dbg.Ex(ex);
        }

        Dbg.Inf($"LLKP BIE {blnEat}");

        if (blnEat == true)
        {
            return((IntPtr)1);
        }
        else
        {
            return(CallNextHookEx(hookHandle, nCode, wParam, lParam));
        }
    }