方法1:
procedure SetKey(SCanCode: byte);
begin
asm
//无论向0x60,还是0x64写东西前都要等状态寄存器OBF变0
@Loop1:
in al, $64
and al, 10b
jnz @Loop1
//向$64端口写命令
mov al, $D2//写键盘输出缓存命令
//mov al, $D3//写鼠标输出缓存命令
out $64, al
//无论向0x60,还是0x64写东西前都要等状态寄存器OBF变0
@Loop2:
in al, $64
and al, 10b
jnz @Loop2
//向$60端口写参数
mov al, SCanCode
out $60, al
end;
end;
方法2:
BOOLEAN
WaitForKeyboardWrite(VOID)
{
INT i;
UCHAR c;
for (i = 0; i < 1000; ++i)
{
KeStallExecutionProcessor(50);
c = READ_PORT_UCHAR(defI8042_CTRL_PORT);
if ((c & defOBUFFER_FULL) == defOBUFFER_FULL)
break;
}
return i ? TRUE : FALSE;
}
VOID PressKeyByScanCode(
IN CONST BYTE ScanCode
)
{
WRITE_PORT_UCHAR(defI8042_CTRL_PORT, 0xd2);