On the basis of the previous article, we describe how to capture the key combinations here, with Ctrl + A as an example
This is done by holding down CTRL with a static member variable to save CTRL is pressed, set to True when CTRL is pressed, and set to False when the CTRL key is lifted
Other key combinations are developed using this example extrapolate.
Header File Declaration
BOOL PreTranslateMessage(MSG* pMsg);
source file definition
BOOLCmfcdlg::P retranslatemessage (msg* pMsg) {Static BOOLM_ctrl_down =false;//This function is initialized when first called if(Pmsg->message = = Wm_keydown) {Switch(Pmsg->wparam) {//vk_a-vk_z is the same as ASCII ' A '-' Z ' (0x41-0x5a) is case insensitive Case ' A '://ctrl + A if(M_ctrl_down) {AfxMessageBox (_t ("Ctrl + A key Down"));return TRUE; } Break; CaseVk_control:m_ctrl_down =true;return TRUE;default:return TRUE; } }if(Pmsg->message = = Wm_keyup) {Switch(Pmsg->wparam) { CaseVk_control:m_ctrl_down =false;return TRUE; } }returnCDialogEx::P retranslatemessage (PMSG);}
MFC dialog Box Dialog response keyboard events (key combination CTRL + a)