Keyboard Input - MFC
-
On a dialog application I would like to capture keyboard input when I press a button and then stop when the button is pressed again. I have included the WM_CHAR and WM_KEYDOWN messages on the dialog, but they are not activated. I can type into an Edit box on just press keys when over the dialog, but breakpoint in
void CKeyBoard_CDNUDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
is never reached. Is there something else I need to do in order to get the keyboard characters pressed. -
On a dialog application I would like to capture keyboard input when I press a button and then stop when the button is pressed again. I have included the WM_CHAR and WM_KEYDOWN messages on the dialog, but they are not activated. I can type into an Edit box on just press keys when over the dialog, but breakpoint in
void CKeyBoard_CDNUDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
is never reached. Is there something else I need to do in order to get the keyboard characters pressed.You need to do it in PreTranslateMessage.
BOOL CMyDialog::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if (pMsg->message == WM_KEYDOWN) { if (pMsg->wParam == some_key_code) { Do_SomeThing(); } } return CDialog::PreTranslateMessage(pMsg); }
-
You need to do it in PreTranslateMessage.
BOOL CMyDialog::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if (pMsg->message == WM_KEYDOWN) { if (pMsg->wParam == some_key_code) { Do_SomeThing(); } } return CDialog::PreTranslateMessage(pMsg); }