yang131

导航

MFC 关于按键状态获取

alt键会阻断消息? moousemove
alt键无法判断,按下一次 并松开一次状态改变一次
#define KeyState GetAsyncKeyState
BOOL bCtrlDown = (KeyState(VK_CONTROL) & 0xff00) > 0 ? TRUE : FALSE;//81 80
BOOL bShiftDown = (KeyState(VK_SHIFT) & 0xff00) > 0 ? TRUE : FALSE;//81 80
BOOL bAltDown = (KeyState(VK_MENU) & 0xff00) > 0 ? TRUE : FALSE;//81 80

CString str;
CString csCtrl;
CString csAlt;
CString csShift;
csCtrl = bCtrlDown == TRUE ? _T("TRUE") : _T("FALSE");
csShift = bShift == TRUE ? _T("TRUE") : _T("FALSE");
csAlt = bAlt == TRUE ? _T("TRUE") : _T("FALSE");
CString cstr;
cstr.Format(_T("Ctrl:%d,Shift:%d,Alt:%d"), bCtrlDown, bShiftDown, bAltDown);
txt2.SetWindowText(cstr);
keydown按键触发
void CKeyDownTestDlg::OnKeyDown(WPARAM wparam)
{
bool bDownValue = true;
if (wparam == VK_CONTROL || wparam == VK_LCONTROL)
{
bCtrl = bDownValue;
}

//这个响应不及时,需要WM_SYSKEYDOWN才能响应
if (wparam == VK_MENU || wparam == VK_LMENU || wparam == VK_RMENU)
{
bAlt = bDownValue;
}
if (wparam == VK_SHIFT || wparam == VK_LSHIFT)
{
bShift = bDownValue;
}
Update();
}

 

posted on 2020-11-24 14:05  NoNight  阅读(1044)  评论(0编辑  收藏  举报