我的钩子在记事本这样的程序中,可以正常的运作,但是比如到了War3.exe这个程序中,每次我按下RShift键的时候,就会在MsgProc中出现两个消息!!??怎么回事??
代码如下://///////////////////////////////////////////
//消息钩子过程
LRESULT CALLBACK GetMsgProc( int code,
    WPARAM wParam,
    LPARAM lParam
)
{
MSG *pMSG = (MSG*)lParam;
if(pMSG ->message == WM_KEYDOWN && pMSG->wParam == VK_SHIFT)
{
g_dwFlag = g_dwFlag%2 + 1;
_itoa_s(g_dwFlag , szBuffer , sizeof(szBuffer) , 10);
::MessageBoxA(NULL, szBuffer, "tip",MB_OK);  //当按下一次Shift键,会弹出不止一次。
}
if(g_dwFlag == 1)
{
if(pMSG->wParam >= 0x41 && pMSG->wParam <= 0x5A)
{
if(pMSG->wParam == g_szKey[0])
{
pMSG->wParam = VK_NUMPAD0;
}
if(pMSG->wParam == g_szKey[1])
{
pMSG->wParam = VK_NUMPAD1;
}
if(pMSG->wParam == g_szKey[2])
{
pMSG->wParam = VK_NUMPAD2;
}
if(pMSG->wParam == g_szKey[3])
{
pMSG->wParam = VK_NUMPAD3;
}
if(pMSG->wParam == g_szKey[4])
{
pMSG->wParam = VK_NUMPAD4;
}
if(pMSG->wParam == g_szKey[5])
{
pMSG->wParam = VK_NUMPAD5;
}
if(pMSG->wParam == g_szKey[6])
{
pMSG->wParam = VK_NUMPAD6;
}
if(pMSG->wParam == g_szKey[7])
{
pMSG->wParam = VK_NUMPAD7;
}
if(pMSG->wParam == g_szKey[8])
{
pMSG->wParam = VK_NUMPAD8;
}
if(pMSG->wParam == g_szKey[9])
{
pMSG->wParam = VK_NUMPAD9;
}
}
} return CallNextHookEx(g_hMSGHook , code ,wParam , lParam);
}/////////////////////////////////////////////////////////////////////
//设置全局消息钩子
void SetKeyHook(TCHAR szBuffer[10])
{
memset(g_szKey, 0  , sizeof(TCHAR) * 10);
memcpy(g_szKey, szBuffer , sizeof(TCHAR)*10);
if(g_hMSGHook != NULL) //已经设置了,那么就进行卸载
{
UnhookKeyHook();
}
if(g_hInst != NULL)
{
g_hMSGHook = SetWindowsHookEx(WH_GETMESSAGE , GetMsgProc , g_hInst ,0 ); //全局钩子
if(g_hMSGHook == NULL)
{
OutputDebugString(_T("Hook Failed \r\n"));
return;
}
}
return;
}

解决方案 »

  1.   

    如何判断??我不是已经判断了WM_KEYDOWN 吗???
    请指点!!!
      

  2.   


    LRESULT CALLBACK KeyboardProc( 
      int code,      // hook code 
      WPARAM wParam,  // virtual-key code 
      LPARAM lParam  // keystroke-message information 


        if((VK_F12==wParam) && (lParam & 0x80000000)==0)) //在这里判断
        { 
            keybd_event(0x57,0,0,0); 
            keybd_event(0x57,0,KEYEVENTF_KEYUP,0); 
            return 1; 
        } 
        else 
        { 
            return CallNextHookEx(g_hKeyboard,code,wParam,lParam); 
        } 

    你参考一下吧 (lParam & 0x80000000)==0)