X
xgw404
Unregistered / Unconfirmed
GUEST, unregistred user!
环境:delphi 7+xp,我的代码如下unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Timer1: TTimer; Memo1: TMemo; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } public { Public declarations } end;const KBC_KEY_CMD = $64; KBC_KEY_DATA = $60; procedure _WinIo_KBCWait4IBE; procedure _WinIo_KeyDown(vKeyCoad:Integer); procedure _WinIo_KeyUp(vKeyCoad:Integer); function _WinIo_Initialize:Boolean; procedure _WinIo_ShutDown;var Form1: TForm1;implementationfunction InitializeWinIo:Boolean;stdcall;external 'WinIo.dll' name'InitializeWinIo';function InstallWinIoDriver(pszWinIoDriverPathString;IsDemandLoaded:boolean=false):Boolean;stdcall;external 'WinIo.dll' name 'InstallWinIoDriver';function RemoveWinIoDriver:Boolean;stdcall;external 'WinIo.dll' name 'RemoveWinIoDriver';function GetPortVal(PortAddr:Word;PortValDWord;bSize:Byte):Boolean;stdcall;external 'WinIo.dll' name 'GetPortVal';function SetPortVal(PortAddr:Word;PortValWord;bSize:Byte):Boolean;stdcall;external 'WinIo.dll' name 'SetPortVal';function GetPhysLong(PhysAddrByte;PhysValDWord):Boolean;stdcall;external 'WinIo.dll' name 'GetPhysLong';function SetPhysLong(PhysAddrByte;PhysValWord):Boolean;stdcall;external 'WinIo.dll' name 'SetPhysLong';function MapPhysToLin(PhysAddrByte;PhysSizeWord;PhysMemHandleHandle)Byte;stdcall;external 'WinIo.dll' name 'MapPhysToLin';function UnMapPhysicalMemory(PhysMemHandle:THandle;LinAddrByte):Boolean;stdcall;external 'WinIo.dll' name 'UnmapPhysicalMemory';procedure ShutdownWinIo;stdcall;external 'WinIo.dll' name'ShutdownWinIo';{$R *.dfm}function _WinIo_Initialize:Boolean;begin Result:=false; try Result:=InitializeWinIo; except Result:=false; end;end;procedure _WinIo_ShutDown;begin ShutdownWinIo;end;procedure _WinIo_KBCWait4IBE; //等待键盘缓冲区为空var dwValWord;begin repeat GetPortVal($64,@dwVal,1); until (dwVal and $2)=0;end;procedure _WinIo_KeyDown(vKeyCoad:Integer);var btScancodeWord;begin btScancode:=MapVirtualKey(vKeyCoad, 0); _WinIo_KBCWait4IBE; SetPortVal($64, $D2, 1); _WinIo_KBCWait4IBE; SetPortVal($60, btScancode, 1);end;procedure _WinIo_KeyUp(vKeyCoad:Integer);var btScancodeWord;begin btScancode:=MapVirtualKey(vKeyCoad, 0); _WinIo_KBCWait4IBE; SetPortVal($64, $D2, 1); _WinIo_KBCWait4IBE; SetPortVal($64, (btScancode or $80), 1);end;procedure TForm1.Button1Click(Sender: TObject);begin memo1.Lines.Clear; timer1.Enabled:=true; _WinIo_KeyDown(66); _WinIo_KeyUp(66); _WinIo_KeyDown(65); _WinIo_KeyUp(65);end;procedure TForm1.FormCreate(Sender: TObject);begin _WinIo_Initialize;end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);begin _WinIo_ShutDown;end;end.程序能编译通过,但好像没什么结果啊