VC获取键盘 虚拟码 扫描码

以下代码:

A.

BOOL CCcPlug_MapleStoryDlg::PreTranslateMessage(MSG* pMsg) 
{
// TODO: Add your specialized code here and/or call the base class

if (pMsg->message == WM_KEYDOWN)
{
//获得键盘扫描码
UINT nScanCode = HIWORD(pMsg->lParam);
SetDlgItemInt(IDC_EDIT4, nScanCode, FALSE);
//获得虚拟键值
UINT nVKCode = ::MapVirtualKey(nScanCode, 3);
SetDlgItemInt(IDC_EDIT3, nVKCode, FALSE); //


//UpdateData(FALSE);
}


return CDialog::PreTranslateMessage(pMsg);
}

为获取键盘按键的虚拟码和扫描码


用到消息:

B.

pWnd->PostMessage(WM_KEYDOWN,VK_D,0x200001);

上的对应关系为:

通过A段代码获得D的扫描码是10进制数值,在转换为16进制后是20

那么在PostMessage消息的第三个参数中应该体现为:0x20 0001

同样S的扫描码为1F

那么应用在PostMessage中的第三个参数为:0x1F 0001

后面的0001表示发送一次按键


注意:

其中第二个参数参见     VC  键盘   虚拟键码表

猜你喜欢

转载自blog.csdn.net/chanchaw/article/details/7562012