View Code
void CKeyOperate::KBCWait4IBE()
{
DWORD dwVal = 0;
do
{
dwVal = _inp(KBC_KEY_CMD);
}
while ((dwVal & 0x2) > 0); // 缓冲区满则继续等待,空则退出,
}
//模拟键盘按下和弹起
void CKeyOperate::keybd_eventEx(IN BYTE bVk,IN BYTE bScan,IN DWORD dwFlags,IN ULONG_PTR dwExtraInfo)
{
long btScancode;
btScancode = MapVirtualKey(bVk,0);
if (dwFlags & KEYEVENTF_KEYUP)
{
btScancode |= 0x80;
}
if (dwFlags & KEYEVENTF_EXTENDEDKEY)
{
KBCWait4IBE(); //等待键盘缓冲区为空
_outp(KBC_KEY_CMD,0xD2); //发送键盘写入命令
KBCWait4IBE();
_outp(KBC_KEY_DATA,0xE0); //写入扩展键标志信息
}
KBCWait4IBE(); //等待键盘缓冲区为空
_outp(KBC_KEY_CMD,0xD2); //发送键盘写入命令
KBCWait4IBE();
_outp(KBC_KEY_DATA,btScancode); //写入扩展键标志信息
}