2个回答
展开全部
方法1(keybd_event):
procedure TForm1.btn2Click(Sender:TObject);
var
h:HWND;
begin
h:=FindWindow('notepad',nil);
SetForegroundWindow(h);
ShowWindow(h,SW_HIDE);
SendKeys('564565465',False);
ShowWindow(h,SW_SHOW);
end;
SendKeys是D7光盘的里的一个sndkey32单元的函数。
方法2(SendMessage):
procedure SendKeysMsg(focushld:hwnd;sSend:string);
var
i:integer; ch:byte;
begin
if focushld=0 then Exit;
i:=1;
while i<=Length(sSend) do
begin
ch:=byte(sSend[i]);
if IsDBCSLeadByte(ch) then
begin
Inc(i);
SendMessage(focushld,WM_IME_CHAR,MakeWord(byte(sSend[i]),ch),0);
end
else
SendMessage(focushld,WM_IME_CHAR,word(ch),0);
Inc(i);
end;
end;
procedure TForm1.btn1Click(Sender:TObject);
var
h:HWND;
begin
h:=FindWindow('notepad',nil);
h:=FindWindowEx(h,0,'Edit',nil);
SendKeysMsg(h,'I服了U');
end;
方法3(WinIo):PS2 Only
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(KBC_KEY_CMD,@dwVal,1);
until (dwVal and $2)=0;
end;
procedure MyKeyPress(vKeyCoad:Integer);
var
btScancode:DWord;
begin
btScancode:=MapVirtualKey(vKeyCoad,0);
KBCWait4IBE;
SetPortVal(KBC_KEY_CMD,$D2,1);
KBCWait4IBE;
SetPortVal(KBC_KEY_DATA,btScancode,1);
KBCWait4IBE;
SetPortVal(KBC_KEY_CMD,$D2,1);
KBCWait4IBE;
SetPortVal(KBC_KEY_DATA,(btScancode or $80),1);
end;
procedure MyKeysPress(KeysString:string);
var
i:Integer;
begin
InitializeWinIo;
for i:=1 to StrLen(Pchar(KeysString)) do
begin
MyKeyPress(vkKeyScan(KeysString[i]));
end;
ShutdownWinIo;
end;
procedure TForm1.btn1Click(Sender:TObject);
var
h:HWND;
begin
h:=FindWindow('notepad',nil);
SetForegroundWindow(h);
MyKeysPress('sdf');
end;
方法4(SendInput):
procedure SendkeyInput(keys:string);
var
I:Integer;
Inputs:array[0..1] of TInput;
begin
Inputs[0].Itype:=INPUT_KEYBOARD;
with Inputs[0].ki do
begin
wScan:=0;
dwFlags:=0;
end;
Inputs[1].Itype:=INPUT_KEYBOARD;
with Inputs[1].ki do
begin
wScan:=0;
dwFlags:=KEYEVENTF_KEYUP;
end;
for I:=1 to Length(keys) do
begin
Inputs[0].ki.wVk:=vkKeyScan(keys[i]);
Inputs[1].ki.wVk:=vkKeyScan(keys[i]);
SendInput(2,Inputs[0],SizeOf(TInput));
end;
end;
h:=FindWindow('notepad',nil);
SetForegroundWindow(h);
SendkeyInput('sdf');
方法5(WH_JOURNALPLAYBACK):
参考 Delphi建键盘鼠标动作纪录与回放。
方法6(谁来?)
procedure TForm1.btn2Click(Sender:TObject);
var
h:HWND;
begin
h:=FindWindow('notepad',nil);
SetForegroundWindow(h);
ShowWindow(h,SW_HIDE);
SendKeys('564565465',False);
ShowWindow(h,SW_SHOW);
end;
SendKeys是D7光盘的里的一个sndkey32单元的函数。
方法2(SendMessage):
procedure SendKeysMsg(focushld:hwnd;sSend:string);
var
i:integer; ch:byte;
begin
if focushld=0 then Exit;
i:=1;
while i<=Length(sSend) do
begin
ch:=byte(sSend[i]);
if IsDBCSLeadByte(ch) then
begin
Inc(i);
SendMessage(focushld,WM_IME_CHAR,MakeWord(byte(sSend[i]),ch),0);
end
else
SendMessage(focushld,WM_IME_CHAR,word(ch),0);
Inc(i);
end;
end;
procedure TForm1.btn1Click(Sender:TObject);
var
h:HWND;
begin
h:=FindWindow('notepad',nil);
h:=FindWindowEx(h,0,'Edit',nil);
SendKeysMsg(h,'I服了U');
end;
方法3(WinIo):PS2 Only
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(KBC_KEY_CMD,@dwVal,1);
until (dwVal and $2)=0;
end;
procedure MyKeyPress(vKeyCoad:Integer);
var
btScancode:DWord;
begin
btScancode:=MapVirtualKey(vKeyCoad,0);
KBCWait4IBE;
SetPortVal(KBC_KEY_CMD,$D2,1);
KBCWait4IBE;
SetPortVal(KBC_KEY_DATA,btScancode,1);
KBCWait4IBE;
SetPortVal(KBC_KEY_CMD,$D2,1);
KBCWait4IBE;
SetPortVal(KBC_KEY_DATA,(btScancode or $80),1);
end;
procedure MyKeysPress(KeysString:string);
var
i:Integer;
begin
InitializeWinIo;
for i:=1 to StrLen(Pchar(KeysString)) do
begin
MyKeyPress(vkKeyScan(KeysString[i]));
end;
ShutdownWinIo;
end;
procedure TForm1.btn1Click(Sender:TObject);
var
h:HWND;
begin
h:=FindWindow('notepad',nil);
SetForegroundWindow(h);
MyKeysPress('sdf');
end;
方法4(SendInput):
procedure SendkeyInput(keys:string);
var
I:Integer;
Inputs:array[0..1] of TInput;
begin
Inputs[0].Itype:=INPUT_KEYBOARD;
with Inputs[0].ki do
begin
wScan:=0;
dwFlags:=0;
end;
Inputs[1].Itype:=INPUT_KEYBOARD;
with Inputs[1].ki do
begin
wScan:=0;
dwFlags:=KEYEVENTF_KEYUP;
end;
for I:=1 to Length(keys) do
begin
Inputs[0].ki.wVk:=vkKeyScan(keys[i]);
Inputs[1].ki.wVk:=vkKeyScan(keys[i]);
SendInput(2,Inputs[0],SizeOf(TInput));
end;
end;
h:=FindWindow('notepad',nil);
SetForegroundWindow(h);
SendkeyInput('sdf');
方法5(WH_JOURNALPLAYBACK):
参考 Delphi建键盘鼠标动作纪录与回放。
方法6(谁来?)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询