HOOK 低层键盘消息---WH_KEYBOARD_LL
HOOK 低层键盘消息---WH_KEYBOARD_LL
代码:屏蔽三个全局快捷键
代码的作用是屏蔽掉注释中的三个快捷键.
LRESULT CALLBACK LowLevelKeyboardProc (INT nCode, WPARAM wParam, LPARAM lParam)
{
// By returning a non-zero value from the hook procedure, the
// message does not get passed to the target window
KBDLLHOOKSTRUCT *pkbhs = (KBDLLHOOKSTRUCT *)lParam;
BOOL bControlKeyDown = 0;
HWND hWnd = GetForegroundWindow();
WCHAR szClassName = {0};
::GetClassName(hWnd, szClassName, MAX_PATH);
switch (nCode)
{
case HC_ACTION:
{
// Check to see if the CTRL key is pressed
bControlKeyDown = GetAsyncKeyState (VK_CONTROL) >> ((sizeof(SHORT) * 8) - 1);
//Disable CTRL+ESC
if (pkbhs->vkCode == VK_ESCAPE && bControlKeyDown)
return 1;
//Disable ALT+TAB
if (pkbhs->vkCode == VK_TAB && pkbhs->flags & LLKHF_ALTDOWN)
return 1;
//Disable ALT+ESC
if (pkbhs->vkCode == VK_ESCAPE && pkbhs->flags & LLKHF_ALTDOWN)
return 1;
break;
}
default:
break;
}
//MessageBoxA(NULL, "aaa", NULL, MB_OK);
return 1;
}
void ChookKeyboardllDlg::OnBnClickedOk()
{
Hook=(HHOOK)SetWindowsHookEx(WH_KEYBOARD_LL,(HOOKPROC)LowLevelKeyboardProc, theApp.m_hInstance,0);
//CDialogEx::OnOK();
}
void ChookKeyboardllDlg::OnBnClickedCancel()
{
if(Hook)
{
BOOL result = UnhookWindowsHookEx((HHOOK)Hook); // 卸载钩子
if (result) Hook = NULL;
}
}
页:
[1]