使用键盘HOOK拦截快捷键

HHOOK OldHook;    //钩子句柄

//---------------------------------------------------------------------------
//*
//这个是钩子的回调函数
long CALLBACK KeyProc(int code, WPARAM wParam, LPARAM lParam)
{
    KBDLLHOOKSTRUCT   *pkbhs;
    if (code < 0)
    {
        return CallNextHookEx(OldHook, code, wParam, lParam);
    }
    pkbhs = (KBDLLHOOKSTRUCT*) lParam;
    if (pkbhs->vkCode == VK_LWIN || pkbhs->vkCode == VK_RWIN)
    {
        return 1;     //封锁win键
    }
    if (pkbhs->vkCode == VK_ESCAPE && GetAsyncKeyState(VK_CONTROL)<0)
    {
        return 1;     //封锁 CTRL+ESC
    }
//    if (pkbhs->vkCode == VK_TAB && pkbhs->flags&LLKHF_ALTDOWN)
//    {
//        return 1;     //封锁 ALT+TAB
//    }
//    if (pkbhs->vkCode == VK_F4 && pkbhs->flags&LLKHF_ALTDOWN)
//    {
//        return 1;     //封锁 ALT+F4
//    }
    if (pkbhs->vkCode == VK_ESCAPE && pkbhs->flags&LLKHF_ALTDOWN)
    {
        return 1;     //封锁 ALT+ESC
    }
//    if (pkbhs->vkCode == VK_SPACE && GetAsyncKeyState(VK_CONTROL)<0)
//    {
//        return 1;     //封锁 CTRL+Space
//    }
    return CallNextHookEx(OldHook, code, wParam, lParam);
}

//---------------------------------------------------------------------------


//*/

//注册钩子
OldHook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)KeyProc, HInstance, 0);

//销毁钩子
UnhookWindowsHookEx( OldHook );

  

posted @ 2014-09-01 17:40  richardw  阅读(1000)  评论(0编辑  收藏  举报