- OnKeyDown, No.
The dialog program originally did not respond directly to keyboard events, and if you use onkeydown you will find that it does not work.
So you want to press "left button", "W Key", "9 keyboard" should be how to respond?
the bool PreTranslateMessage (msg* PMSG) function of the overloaded base class
- The simplest keyboard response function
Header File declaration:
BOOL PreTranslateMessage (msg* pMsg);
source file Definition:
BOOL Cmfcdlg::P retranslatemessage (msg* pMsg)
{
if (pmsg->message = = Wm_keydown)
{
Switch (Pmsg->wparam)
{
Case vk_escape://Shielded ESCAPE key
return TRUE;
Vk_a-vk_z is the same as ASCII ' A '-' Z ' (0x41-0x5a) is case insensitive
Case ' A ':
AfxMessageBox (_t ("A key Down"); return TRUE;
Case Vk_right:
AfxMessageBox (_t ("-Key Down")); return TRUE;
Case ' 0 ':
AfxMessageBox (_t ("0 key Down"); return TRUE;
Default
return TRUE;
}
}
return CDialogEx::P retranslatemessage (PMSG);
}
MFC dialog Box Dialog response keyboard events