捕獲組合鍵 鍵盤組合鍵
阿新 • • 發佈:2019-02-05
① 捕獲【Ctrl、Ctrl+Alt】和【Ctrl+Alt+Shift】這樣的組合鍵:
BOOL CTestDlg::PreTranslateMessage(MSG* pMsg) { if(pMsg->message==WM_KEYDOWN) { BOOL bCtrl=::GetKeyState(VK_CONTROL)&0x8000; BOOL bShift=::GetKeyState(VK_SHIFT)&0x8000; BOOL bAlt=::GetKeyState(VK_MENU)&0x8000; switch(pMsg->wParam) { case VK_DELETE: if(bCtrl&&bAlt&&bShift) MessageBox("你按下的是Ctrl+Shift+Alt+Delete組合鍵","資訊提示",MB_OK); else if(bCtrl&&bShift) MessageBox("你按下的是Ctrl+Shift+Delete組合鍵", "資訊提示",MB_OK); else if(bCtrl) MessageBox("你按下的是Ctrl+Delete組合鍵", "資訊提示",MB_OK); return TRUE; case VK_INSERT: if(bCtrl&&bAlt&&bShift) MessageBox("你按下的是Ctrl+Shift+Alt+Insert組合鍵","資訊提示",MB_OK); else if(bCtrl&&bAlt) MessageBox("你按下的是Ctrl+Alt+Insert組合鍵","資訊提示",MB_OK); else if(bCtrl) MessageBox("你按下的是Ctrl+Insert組合鍵","資訊提示",MB_OK); return TRUE; } }
BOOL CTestDlg::PreTranslateMessage(MSG* pMsg)
{
char nChar = pMsg->wParam;
if(nChar == 'Z' && ((GetAsyncKeyState( VK_LCONTROL ) & 0x8000)))
{
AfxMessageBox("ctrl + z");
}
return CDialog::PreTranslateMessage(pMsg);
}
[轉自]