键盘钩子修改键值

在修改键值的时候,需要挂住WH_GETMSG 挂住WM_KEYBORD是不可以的。一个按键 你会不清楚对方使用WM_KEYdwon KEYUP WM_CHAR哪个消息的,最好全部挂钩



#define DLL_EXPORTS



#include"keyboard.h"


HMODULE CHookKeyBord::s_DllHandle = NULL;
HHOOK   CHookKeyBord::m_hKeyBordHook = NULL;


LRESULT CHookKeyBord::KeyboardProc(int cCode, WPARAM wParam, LPARAM lParam )
{
    MSG* msg = (MSG*) lParam;
     cout<<" msg "<<msg->wParam<<endl;
    if(msg->message == WM_KEYDOWN || msg->message == WM_KEYUP ||msg->message == WM_CHAR)
    {
        msg->wParam += 1;
        cout<<msg->wParam<<endl;
        return 1;
    }
    return CallNextHookEx(CHookKeyBord::m_hKeyBordHook,cCode,wParam,lParam);
}
CHookKeyBord::CHookKeyBord()
{
    
}


CHookKeyBord::~CHookKeyBord()
{


}
void CHookKeyBord::SetKeyBordHook(DWORD dwPid /* = 0 */)
{
    CHookKeyBord::m_hKeyBordHook = SetWindowsHookEx(WH_GETMESSAGE,CHookKeyBord::KeyboardProc,CHookKeyBord::s_DllHandle,dwPid);
}




BOOL WINAPI DllMain(__in HANDLE _HDllHandle, __in DWORD _Reason, __in_opt LPVOID _Reserved)
{
    CHookKeyBord::s_DllHandle =(HMODULE) _HDllHandle;
    return true;
}

你可能感兴趣的:(键盘钩子修改键值)