本意是想利用WINIO记录和模拟键盘的输入,但在记录的时候连鼠标的输入都记下了。。请问怎样才可以只记录键盘的输入?readKey()这个函数是用来记录的
function readKey():Integer;
var
valKey : Byte;
begin
asm
//应该在这里加上判断,只是完全不会汇编所以请各位指点一下,不胜感激
in al, $60
mov valKey,al
@loop:
end;
SetKey(0);
Result := valKey;
end;
function InitializeWinIo:Boolean;stdcall;external 'WinIo.dll' name'InitializeWinIo';
function InstallWinIoDriver(pszWinIoDriverPath:PString;IsDemandLoaded:boolean=false):Boolean;stdcall;external 'WinIo.dll' name 'InstallWinIoDriver';
function RemoveWinIoDriver:Boolean;stdcall;external 'WinIo.dll' name 'RemoveWinIoDriver';
function GetPortVal(PortAddr:Word;PortVal:PDWord;bSize:Byte):Boolean;stdcall;external 'WinIo.dll' name 'GetPortVal';
function SetPortVal(PortAddr:Word;PortVal:DWord;bSize:Byte):Boolean;stdcall;external 'WinIo.dll' name 'SetPortVal';
function GetPhysLong(PhysAddr:PByte;PhysVal:PDWord):Boolean;stdcall;external 'WinIo.dll' name 'GetPhysLong';
function SetPhysLong(PhysAddr:PByte;PhysVal:DWord):Boolean;stdcall;external 'WinIo.dll' name 'SetPhysLong';
function MapPhysToLin(PhysAddr:PByte;PhysSize:DWord;PhysMemHandle:PHandle):PByte;stdcall;external 'WinIo.dll' name 'MapPhysToLin';
function UnMapPhysicalMemory(PhysMemHandle:THandle;LinAddr:PByte):Boolean;stdcall;external 'WinIo.dll' name 'UnmapPhysicalMemory';
procedure ShutdownWinIo;stdcall;external 'WinIo.dll' name'ShutdownWinIo';
procedure KBCWait4IBE; //等待键盘缓冲区为空
var
dwVal:DWord;
begin
repeat
GetPortVal($64,@dwVal,1);
until (dwVal and $2)=0;
end;
procedure MyKeyDown(vKeyCoad:Integer);
var
btScancode:DWord;
begin
btScancode:=MapVirtualKey(vKeyCoad, 0);
KBCWait4IBE;
if SetPortVal($64, $D2, 2) then
begin
form3.Memo1.lines.add('down = a');
end;
KBCWait4IBE;
SetPortVal($60, btScancode, 2);
end;
procedure MyKeyUp(vKeyCoad:Integer);
var
btScancode:DWord;
begin
btScancode:=MapVirtualKey(vKeyCoad, 0);
KBCWait4IBE;
procedure SetKey(SCanCode: byte);
begin
asm
//无论向0x60,还是0x64写东西前都要等状态寄存器OBF变0
@Loop1:
in al, $64
and al, 10b
jnz @Loop1
//向$64端口写命令
// mov al, 0xD2//写键盘输出缓存命令
mov al, $D2//写鼠标输出缓存命令
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;
//自己写的
function readKey():Integer;
var
valKey : Byte;
begin
asm
//应该在这里加上判断,只是完全不会汇编所以请各位指点一下,不胜感激
in al, $60
mov valKey,al
@loop:
end;
SetKey(0);
Result := valKey;
end;
procedure TForm3.Button1Click(Sender: TObject);
begin
if not InitializeWinIo then begin
Messagebox(handle,'初始化失败!','提示',MB_OK+MB_IconError)
end;
TButton(Sender).Enabled := False;
end;
procedure TForm3.Button2Click(Sender: TObject);
begin
Timer1.Enabled := not Timer1.Enabled;
end;
procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ShutdownWinIo;
end;
procedure TForm3.Timer1Timer(Sender: TObject);
var
vkeyCode : Integer;
keyData : Byte;
begin
keyData := readKey();
vkeyCode := MapVirtualKey(keyData,1);
if vkeyCode > 0 then
begin
Form3.Memo1.Lines.Add(Char(vkeyCode));
end;
end;