MFC如何实现组合键盘响应
MFC怎么实现组合键盘响应
BOOL CzxczDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: 在此添加专用代码和/或调用基类
if (pMsg->message == WM_KEYDOWN)
{
if (pMsg->wParam ==0x41) //vk_ 或16进制码
{
OnBnClickedButton1(); //函数
}
}
return CDialogEx::PreTranslateMessage(pMsg);
}
已经知道响应但是键盘,但是怎么响应组合键盘,求教各位大神
------解决方案--------------------
按键Down事件中,检查是否有shift、ctrl等键按下,如果有记录到一个变量中,如bShift=true
按键Up事件中,bShift=false
别的按键事件处理中检查对应的标志是否有设置
------解决方案--------------------
可以注册热键 RegisterHotkey
------解决方案--------------------
------解决方案--------------------
BOOL CzxczDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: 在此添加专用代码和/或调用基类
if (pMsg->message == WM_KEYDOWN)
{
if (pMsg->wParam ==0x41) //vk_ 或16进制码
{
OnBnClickedButton1(); //函数
}
}
return CDialogEx::PreTranslateMessage(pMsg);
}
已经知道响应但是键盘,但是怎么响应组合键盘,求教各位大神
------解决方案--------------------
按键Down事件中,检查是否有shift、ctrl等键按下,如果有记录到一个变量中,如bShift=true
按键Up事件中,bShift=false
别的按键事件处理中检查对应的标志是否有设置
------解决方案--------------------
可以注册热键 RegisterHotkey
------解决方案--------------------
if (pMsg->message == WM_KEYDOWN)
{
if (pMsg->wParam == 'F' && GetKeyState(VK_CONTROL) && pMsg->lParam & 0x20000000)
{
MessageBox(L"Ctrl+ALT+F");
}
else if (pMsg->wParam == 'F' && GetKeyState(VK_CONTROL) && !(pMsg->lParam & 0x20000000))
{
MessageBox(L"Ctrl+F");
}
}
else if (pMsg->message == WM_SYSKEYDOWN)
{
if (pMsg->wParam == 'F' && pMsg->lParam & 0x20000000)
{
MessageBox(L"ALT+F");
}
}
------解决方案--------------------
////快捷键 虚拟码
#define VK_OEM_2 0xBF // '/?' for US
LRESULT CALLBACK KeyboardProc(
int code, // hook code
WPARAM wParam, // virtual-key code
LPARAM lParam // keystroke-message information
)
{
if (((DWORD)lParam&0x40000000) && (HC_ACTION==code))
{
//Ctrl+Shift+字符 不能含Alt
if (!(GetKeyState(VK_CONTROL) & 0x80) && !(GetKeyState(VK_SHIFT) & 0x80) && (GetKeyState(VK_MENU) & 0x80))
{
switch(wParam)
{
case 'P':
{
...
return TRUE;
}
break;
case 'L':
{
...
return TRUE;
}
break;
case VK_OEM_2://退出
{
...
return TRUE;
}
break;
default:
break;
}
}
}
return CallNextHookEx(g_hKeyboard2,code,wParam,lParam);
//return 1;
}