You can intercept and respond to messages you care about by overloading the virtual function PreTranslateMessage():
The following interception and response to the interception and response of the keyboard Enter message
This is how the dialog box responds to the keyboard Enter message:
BOOL C**Dlg::PreTranslateMessage(MSG* pMsg)
{
//Determine whether it is a keyboard message
if (WM_KEYFIRST <= pMsg->message && pMsg->message <= WM_KEYLAST)
{
//Determine whether the keyboard Enter key is pressed
if(pMsg->wParam==VK_RETURN)
{
return TRUE;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
}
}
return CDialog::PreTranslateMessage(pMsg);
}
Here are some keyboard values:
Symbolic form hexadecimal form description VK_LBUTTON 01 left mouse button VK_RBUTTON 02 Right mouse button VK_CANCEL 03 Control-break procedure VK_MBUTTON 04 Middle mouse button VK_BACK 08 BACKSPACE 键 VK_TAB 09 TAB 键 VK_CLEAR 0C CLEAR 键 VK_RETURN 0D ENTER key VK_SHIFT 10 SHIFT 键 VK_CONTROL 11 CTRL key VK_MENU 12 ALT Key VK_PAUSE 13 PAUSE Key VK_CAPITAL 14 CAPS LOCK 键 VK_ESCAPE 1B ESC key VK_SPACE 20 SPACEBAR VK_PRIOR 21 PAGE UP 键 VK_NEXT 22 PAGE DOWN 键 UK_END 23 END 键 VK_HOME 24 HOME Key VK_LEFT 25 LEFT ARROW 键 VK_UP 26 UP ARROW 键 VK_RIGHT 27 RIGHT ARROW 键 VK_DOWN 28 DOWN ARROW 键 VK_SELECT 29 SELECT key VK_EXECUTE 2B EXECUTE 键 VK_SNAPSHOT 2C PRINT SCREEN key (for Windows 3.0 and later) VK_INSERT 2D INS key VK_DELETE 2E DEL 键 VK_HELP 2F HELP Key VK_LWIN 5B Left Windows key (Microsoft natural keyboard) VK_RWIN 5C Right Windows key (Microsoft natural keyboard) VK_APPS 5D Applications key (Microsoft natural keyboard) VK_NUMPAD0 60 0 key on numeric keypad VK_NUMPAD1 61 1 key on the numeric keypad VK_NUMPAD2 62 2 keys on numeric keypad VK_NUMPAD3 63 3 keys on the numeric keypad VK_NUMPAD4 4 keys on 64 numeric keypad VK_NUMPAD5 65 5 keys on numeric keypad VK_NUMPAD6 66 keys on numeric keypad VK_NUMPAD7 67 7 key on numeric keypad VK_NUMPAD8 68 8 keys on numeric keypad VK_NUMPAD9 69 9 key on numeric keypad VK_MULTIPLY 6A Multiply key VK_ADD 6B Add键 VK_SEPARATOR 6C Separator 键 VK_SUBTRACT 6D Subtract key VK_DECIMAL 6E Decimal Key VK_DIVIDE 6F Divide key VK_F1 70 F1 key VK_F2 71 F2 key VK_F3 72 F3 key VK_F4 73 F4 key VK_F5 74 F5 key VK_F6 75 F6 key VK_F7 76 F7 key VK_F8 77 F8 key VK_F9 78 F9 key VK_F10 79 F10 key VK_F11 7A F11 key VK_F12 7B F12 key VK_F13 7C F13 key VK_F14 7D F14 key VK_F15 7 E F15 key VK_F16 7F F16 key VK_F17 80H F17 key VK_F18 81H F18 key VK_F19 82H F19 key VK_F20 83H F20 key VK_F21 84H F21 key VK_F22 85H F22 key VK_F23 86H F23 key VK_F24 87H F24 key VK_NUMLOCK 90 NUM LOCK 键 VK_SCROLL 91 SCROLL LOCK 键 VK_ATTN F6 Attn key VK_CRSEL F7 CrSel 键 VK_EXSEL F8 ExSel key VK_EREOF F9 Erase EOF 键 VK_PLAY FA Play 键 VK_ZOOM FB Zoom key VK_OEM_CLEAR FE Clear 键