Suppress task switch keys (winkey, alt-tab, alt-esc, ctrl-esc) using low-level keyboard hook

Posted by matt on Stack Overflow See other posts from Stack Overflow or by matt
Published on 2010-03-22T07:33:32Z Indexed on 2010/03/22 7:41 UTC
Read the original article Hit count: 430

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about c#