abhi312
abhi312

Reputation: 362

Multiple Key Press handling in mfc

How to handle multiple key press in MFC. I have tried for few key combinations.But How to generalize for all key combination.

BOOL Test::PreTranslateMessage(MSG* pMsg){
   if(pMsg->message==WM_KEYDOWN ) 
   {    
       if(pMsg->wParam == 'C' || pMsg->wParam == 'V')
       {
           if(GetKeyState(VK_CONTROL) < 0){
           }
       }
   }
}

Upvotes: 1

Views: 2031

Answers (2)

Flaviu_
Flaviu_

Reputation: 1371

The right way is to handle WM_CUT, WM_COPY and WM_PASTE, because the copy/paste operations could be completed not only Ctrl+C, but CTrl+Insert, and so on ... if you want to handle these things ...

"PreTranslateMessage is dangerous territory": really true ! Take care !

Upvotes: 2

xMRi
xMRi

Reputation: 15375

You can GetKeyState and check what keys are down.

if ((::GetKeyState(_T('C')) & 0x8000)!=0 && 
    (::GetKeyState(_T('V')) & 0x8000)!=0)
    // C and V are down...

You can do this check whenever a WM_KEYDOWN arrives in your PreTranslateMessage function. Using this for normal keys like accelerating will work. The MFC also does its checks for accelerators in the PreTranslateMessage functions.

You should always use GetKeyState because this function check what keys where down/up when the current message you received from the message queue was processed.

Upvotes: 3

Related Questions