1. 程式人生 > >捕獲組合鍵 鍵盤組合鍵

捕獲組合鍵 鍵盤組合鍵

① 捕獲【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;  
        }  
    }  
} ② 捕獲【Ctrl + Z】組合鍵:
BOOL CTestDlg::PreTranslateMessage(MSG* pMsg)   
{  
    char nChar = pMsg->wParam;  
    if(nChar == 'Z' && ((GetAsyncKeyState( VK_LCONTROL ) & 0x8000)))  
    {  
        AfxMessageBox("ctrl + z");  
    }  
    return CDialog::PreTranslateMessage(pMsg);  
} 

[轉自]
http://blog.csdn.net/dijkstar/article/details/8944131