views:

251

answers:

1

I'm trying to suppress task switch keys (such as winkey, alt-tab, alt-esc, ctrl-esc, etc.) by using a low-level keyboard hook.

I'm using the following LowLevelKeyboardProc callback:

IntPtr HookCallback(int nCode, IntPtr wParam, ref KBDLLHOOKSTRUCT lParam) 
{
    if (nCode >= 0)
    {
            bool suppress = false;

            // Suppress left and right windows keys.
            if (lParam.Key == VK_LWIN || lParam.Key == VK_RWIN) 
                suppress = true;

            // Suppress alt-tab.
            if (lParam.Key == VK_TAB && HasAltModifier(lParam.Flags)) 
                suppress = true;

            // Suppress alt-escape.
            if (lParam.Key == VK_ESCAPE && HasAltModifier(lParam.Flags)) 
                suppress = true;

            // Suppress ctrl-escape.
            /* How do I hook CTRL-ESCAPE ? */

            // Suppress keys by returning 1.
            if (suppress) 
                return new IntPtr(1);
    }
    return CallNextHookEx(HookID, nCode, wParam, ref lParam);
}

bool HasAltModifier(int flags)
{
    return (flags & 0x20) == 0x20;
}

However, I'm at a loss as to how to suppress the CTRL-ESC combination. Any suggestions? Thanks.

+1  A: 

This should do the trick:

bool ControlDown = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
if (lParam.Key == VK_ESCAPE && ControlDown)
    suppress = true;
RaptorFactor