码迷,mamicode.com
首页 > 其他好文 > 详细

HOOK 底层键盘消息---WH_KEYBOARD_LL

时间:2015-08-21 11:22:38      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:

代码:屏蔽三个全局快捷键

代码的作用是屏蔽掉注释中的三个快捷键.


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[MAX_PATH] = {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()
{
	// TODO: 在此添加控件通知处理程序代码
	Hook=(HHOOK)SetWindowsHookEx(WH_KEYBOARD_LL,(HOOKPROC)LowLevelKeyboardProc, theApp.m_hInstance,0); 
	//CDialogEx::OnOK();
}


void ChookKeyboardllDlg::OnBnClickedCancel()
{
	// TODO: 在此添加控件通知处理程序代码
	if(Hook)
	{
		BOOL result = UnhookWindowsHookEx((HHOOK)Hook); // 卸载钩子
		if (result) Hook = NULL;
	}
	//CDialogEx::OnCancel();
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

HOOK 底层键盘消息---WH_KEYBOARD_LL

标签:

原文地址:http://blog.csdn.net/jiangqin115/article/details/47831039

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!