15,981
社区成员




WM_KEYDOWN
wParam
virtual-key code
lParam
0~15 repeat code
16~23 scan code
24 extended key (flag)
25~28 not used
30 previous key state (flag)
31 transition state (flag)
For enhanced 101- and 102-key keyboards, extended keys are the right ALT and CTRL keys on the main section of the keyboard; the INS, DEL, HOME, END, PAGE UP, PAGE DOWN, and arrow keys in the clusters to the left of the numeric keypad; and the divide (/) and ENTER keys in the numeric keypad. Other keyboards may support the extended-key bit in the lParam parameter.
不过还是不知道 #4 的代码为何在 wParam >= VK_PRIOR && wParam <= VK_HELP 时要强加一个标志位给 lParam,而非检测标志位。我觉得在收到 WM_KEYDOWN 消息时,直接检测标志位应该就能知道这个是来自哪个键:if (wParam == VK_RETURN) {
if (lParam & (1 << 24)) {
// 小键盘Enter
} else {
// 主键盘Enter
}
}
#if 1 // use lParam = scancode.
if(pMsg->message == WM_KEYDOWN)
{// 0x21 0x2F
if (pMsg->wParam >= VK_PRIOR && pMsg->wParam <= VK_HELP)
{// for keypad (小键盘)
pMsg->lParam |= 0x01000000;// bit24
}
char str[40]={0};
if(GetKeyNameText(pMsg->lParam, str,40) > 0)
{
afxDump << str << "\n";
}
}
#endif
return CDialog::PreTranslateMessage(pMsg);
小键盘为 "Num Enter"
大键盘为 "Enter"