HHOOK glhHook;//用于存放钩子过程的指针 HINSTANCE dllHwnd;//用于存放当前dll的实例的句柄 ///////////////////////////////////////////////////////////////////////////// // CMyQQDLLAppBEGIN_MESSAGE_MAP(CMyQQDLLApp, CWinApp) //{{AFX_MSG_MAP(CMyQQDLLApp) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG_MAP END_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////// // CMyQQDLLApp constructionCMyQQDLLApp::CMyQQDLLApp() { // TODO: add construction code here, // Place all significant initialization in InitInstance m_hHook=NULL; //dllHwnd=this->m_hInstance; } LRESULT CALLBACK KeyboardPro(int nCode,WPARAM wParam,LPARAM lParam) { switch(wParam) { case '1': AfxMessageBox("1");break; case '2': AfxMessageBox("2");break; } return CallNextHookEx(glhHook,nCode,wParam,lParam); } ///////////////////////////////////////////////////////////////////////////// // The one and only CMyQQDLLApp objectCMyQQDLLApp theApp;BOOL InstallHook() { glhHook=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardPro,theApp.m_hInstance,0);//安装全局键盘钩子 if(glhHook) { return TRUE; } else { return FALSE; } }
if(true|(lParam & 0x80000000))//&&(lParam & 0x20000000))//bit 31Specifies the transition state. The value is 0 if the key is being pressed and 1 if it is being released. //bit24 if The value is 1 if the key is an extended key; otherwise, it is 0.
HINSTANCE dllHwnd;//用于存放当前dll的实例的句柄
/////////////////////////////////////////////////////////////////////////////
// CMyQQDLLAppBEGIN_MESSAGE_MAP(CMyQQDLLApp, CWinApp)
//{{AFX_MSG_MAP(CMyQQDLLApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CMyQQDLLApp constructionCMyQQDLLApp::CMyQQDLLApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
m_hHook=NULL;
//dllHwnd=this->m_hInstance;
}
LRESULT CALLBACK KeyboardPro(int nCode,WPARAM wParam,LPARAM lParam)
{
switch(wParam)
{
case '1': AfxMessageBox("1");break;
case '2': AfxMessageBox("2");break;
}
return CallNextHookEx(glhHook,nCode,wParam,lParam);
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CMyQQDLLApp objectCMyQQDLLApp theApp;BOOL InstallHook()
{ glhHook=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardPro,theApp.m_hInstance,0);//安装全局键盘钩子
if(glhHook)
{
return TRUE;
}
else
{
return FALSE;
}
}
if(true|(lParam & 0x80000000))//&&(lParam & 0x20000000))//bit 31Specifies the transition state. The value is 0 if the key is being pressed and 1 if it is being released.
//bit24 if The value is 1 if the key is an extended key; otherwise, it is 0.
LRESULT WINAPI War3GetMsgProc(int nCode,WPARAM wParam,LPARAM lParam)
{
//HWND hTargetHwnd=GetActiveWindow();//得到活动窗口
if (nCode == HC_ACTION)
{
PMSG msg = (PMSG)lParam;
if (msg->message == WM_KEYDOWN || msg->message == WM_KEYUP)
{
for( int i = 0; i < 256; i++)
{
if( 0 == g_dwKey[i] || 0 == g_dwValue[i] )
break;
if( msg->wParam == g_dwKey[i] )
{
msg->wParam = g_dwValue[i];
break;
}
/*if( msg->wParam == VK_LWIN )
{
msg->wParam = 65;
return TRUE;
break;
}*/
}
}
}
return CallNextHookEx(hWar3Hook, nCode, wParam, lParam);
}
{
=============
看清楚点啊,老兄,你这个是消息钩子啊,人家是键盘钩子啊呵呵 已经认识到无知了 那个快捷键的判断怎么做啊
=================
我不上面不是说了吗,将如果 lParam & 0x8000结果为0表示按下,为1表示弹起,只用这个只处理一次就是了
if((VK_LCONTROL && 1==(lParam&0x8000) ) || (VK_RCONTROL1==(lParam&0x8000)))
UnhookWindowsHookEx(glhHook);
大哥钩子完事的时候要 有返回值呀 return 1;