Let's take a look at the keyboard virtual code before talking about shortcut key programming,
There are two types of keyboard messages:
Non-system key wm_keydown wm_keyup
System key wm_syskeydown wm_syskeyup
Virtual Value
Vk_lbutton 01 left mouse button
Vk_rbutton 02 right-click
Vk_cancel 03 control-Break Process
Vk_mbutton 04
Vk_back 08 backspace key
Vk_tab 09 Tab key
Vk_clear 0C clear key
Vk_return 0d enter
Vk_shift 10 shift key
Vk_control 11 CTRL
Vk_menu 12 Alt key
Vk_pause 13 pause key
Vk_capital 14 Caps Lock key
Vk_escape 1B ESC key
Vk_space 20 spacebar
Vk_prior 21 page up key
Vk_next 22 page down key
Vk_end 23 end key
Vk_home 24 Home Key
Vk_left 25 left arrow
Vk_up 26 up arrow key
Vk_right 27 right arrow key
Vk_down 28 down arrow key
Vk_select 29 select key
Vk_execute 2B execute key
Vk_snapshot 2C print screen key
Vk_insert 2D ins key
Vk_delete 2E DEL key
Vk_help 2f help key
For numeric and numeric keys on non-keypad, simply add the key to single quotes.
For example, key A: 'A'
1 key: '1'
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 key 0 on the keypad
Vk_numpad1 61 key on the keypad
Vk_numpad2 62 key 2 on the keypad
Vk_numpad3 63 key 3 on the keypad
Vk_numpad4 64 key 4 on the keypad
Vk_numpad5 65 key 5 on the keypad
Vk_numpad6 66 Key 6 on the keypad
Vk_numpad7 67 key 7 on the keypad
Vk_numpad8 68: 8 keys on the keypad
Vk_numpad9 69 key on the keypad
Vk_multiply 6a multiply key
Vk_add 6B add key
Vk_separator 6C separator key
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 7E F15 key
Vk_f16 7f F16 key
Vk_f17 80 h f17 key
Vk_f18 81 h F18 key
Vk_f19 82 H F19 key
Vk_f20 83 H F20 key
Vk_f21 84 h F21 key
Vk_f22 85 H f22 key
Vk_f23 86 H F23 key
Vk_f24 87 h f24 key
Vk_numlock 90 Num Lock key
Vk_scroll 91 scroll Lock key
Vk_attn F6 Attn key
Vk_crsel F7 crsel key
Vk_exsel F8 exsel key
Vk_ereof F9 erase EOF key
Vk_play fa play key
Vk_zoom FB zoom key
Vk_oem_clear Fe clear key
Add the virtual function pretranslatemessage to the cxxxapp class in a single-document application.
Bool chbplayerapp: pretranslatemessage (MSG * PMSG)
{
// Todo: add your specialized code here and/or call the base class
If (PMSG-> message = wm_keydown)
{
Switch (PMSG-> wparam)
{
// Shield the ESC message
Case vk_escape:
Return true;
Break;
// Block the Enter key message
Case vk_return:
Return true;
Break;
// Ctrl + c
Case 'C ':
If (: getkeystate (vk_control) <0)
{
}
Break;
// Ctrl + Shift + S
Case's ':
If (: getkeystate (vk_control) <0) & (: getkeystate (vk_shift) <0 ))
{
}
Return cwinapp: pretranslatemessage (PMSG );
}
Add a keyboard response event in the dialog box
1. Add Windows message handle in classview add WM-KEYDOWN and WM-KEYUP, add your Ural functions add pretranslatemessage
2. Add bool ** DLG: pretranslatemessage (MSG * PMSG)
{
If (PMSG-> message = wm_keydown)
{
If (PMSG-> wparam = vk_return) // directly use a virtual code instead of the corresponding key.
Setinfo (wdk_ OK); // enter the corresponding OK
}
If (PMSG-> message = wm_keydown)
{
If (PMSG-> wparam = vk_back) // you can directly use a virtual code instead of the corresponding key.
Setinfo (wdk_c); // Delete the backspace
}
Return cdialog: pretranslatemessage (PMSG );
}
3. usage of the key combination: (In this example, the CTRL + x key is returned)
Bool cmydilog: pretranslatemessage (MSG * PMSG)
{
If (PMSG-> message = wm_keydown)
{
Switch (PMSG-> wparam)
{
Case vk_escape:
Setfocus ();
Return true;
Case 'X ':
If (: getkeystate (vk_control) <0
MessageBox ("hello ");
Return true;
}
}
Return cdialog: pretranslatemessage (PMSG );
}
F10 and ALT arent picked up by wm_keydown, you need wm_syskeydown.
You need to add: Case wm_syskeydown:
If (PMSG-> wparam = vk_f10)
Trace ("F10/N ");
Break;