屏蔽WIN、ALT+TAB、CTRL+ESC键的低级键盘钩子

回调函数:

LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) { BOOL fEatKeystroke = FALSE; PKBDLLHOOKSTRUCT p = NULL;

if (nCode == HC_ACTION)
{
    p = (PKBDLLHOOKSTRUCT) lParam;
    switch (wParam)
    {
        case WM_KEYDOWN:
            // Backdoor to user information
            if (p->vkCode == VK_F8)
            {
                ::MessageBox(NULL,"Let's make things better and better!\n","HQ Tech",MB_OK);
                break;
            }
        case WM_SYSKEYDOWN:
        case WM_KEYUP:
        case WM_SYSKEYUP:
            fEatKeystroke = (p->vkCode == VK_LWIN) || (p->vkCode == VK_RWIN) ||  // 屏蔽Win
                            // 屏蔽Alt+Tab
                            ((p->vkCode == VK_TAB) && ((p->flags & LLKHF_ALTDOWN) != 0)) ||
                            // 屏蔽Alt+Esc
                            ((p->vkCode == VK_ESCAPE) && ((p->flags & LLKHF_ALTDOWN) != 0)) ||
                            // 屏蔽Ctrl+Esc
                            ((p->vkCode == VK_ESCAPE) && ((GetKeyState(VK_CONTROL) & 0x8000) != 0));
            break;
        default:
            break;
  }
}

return (fEatKeystroke ? TRUE : CallNextHookEx(glhHook,nCode,wParam,lParam)); }

安装及卸载钩子:

void _stdcall StartKeyMask() { // 安装钩子 glhHook = SetWindowsHookEx(WH_KEYBOARD_LL,LowLevelKeyboardProc,glhInstance,0); }

void _stdcall StopKeyMask() { // 卸载钩子 if (glhHook!=NULL) UnhookWindowsHookEx(glhHook); }

支持原创技术分享,据说打赏我的人,都找到了女朋友!