安装一个 键盘钩子
SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)HookFun,(HINSTANCE)AfxGetApp()->m_hInstance,0);回调函数
LRESULT CALLBACK HookFun(int code,WPARAM wParam,LPARAM lParam)
{
MSG *msg=(MSG*)lParam;
if (msg->message==WM_CHAR)
{
AfxMessageBox("Hook Run");
}
return 1;
}LRESULT CALLBACK HookFun(int code,WPARAM wParam,LPARAM lParam)
{
if (code==HC_ACTION && (lParam & 0xc000ffff) == 1)
{
AfxMessageBox("Hook Run");
}
return 1;
}发觉第二种有响应 第一种为什么没响应?
都是网上找的代码 没搞明白 有人能解释下不?
SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)HookFun,(HINSTANCE)AfxGetApp()->m_hInstance,0);回调函数
LRESULT CALLBACK HookFun(int code,WPARAM wParam,LPARAM lParam)
{
MSG *msg=(MSG*)lParam;
if (msg->message==WM_CHAR)
{
AfxMessageBox("Hook Run");
}
return 1;
}LRESULT CALLBACK HookFun(int code,WPARAM wParam,LPARAM lParam)
{
if (code==HC_ACTION && (lParam & 0xc000ffff) == 1)
{
AfxMessageBox("Hook Run");
}
return 1;
}发觉第二种有响应 第一种为什么没响应?
都是网上找的代码 没搞明白 有人能解释下不?
[in] Specifies the virtual-key code of the key that generated the keystroke message.
lParam
[in] Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag. For more information about the lParam parameter, see Keystroke Message Flags. This parameter can be one or more of the following values.
SetWindowsHookEx(WH_GETMESSAGE,(HOOKPROC)RecHook,(HINSTANCE)AfxGetApp()->m_hInstance,0);第一种还是没反应
恩 使用 WH_KEYBOARD 可以取得按键值。不过处理键值有点累 要枚举
我觉得 MSG的 可能方便些
{ MSG *msg=(MSG*)lParam;
if (msg->message==WM_CHAR)
{
MessageBox(NULL,(CString)msg->wParam,NULL,MB_OK);
}
return 1;
}就是 按什么键提示什么键
所以 不支持PreTranslateMessage取得消息 所以想用钩子来取得按键明天来看 谢谢回复
加上 一个按钮 用来安装钩子 SetWindowsHookEx
安装钩子后
需要的结果就是 点什么 提示什么