【DELPHI】 对多个窗体(最小化)模拟键盘输入

对多个最少化的窗体模拟键盘输入。指定隐藏的窗体也行。... 对多个最少化的窗体模拟键盘输入。
指定隐藏的窗体也行。
展开
 我来答
手机用户57830
2009-01-14 · 超过31用户采纳过TA的回答
知道答主
回答量:78
采纳率:0%
帮助的人:0
展开全部
方法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(谁来?)
TheFiend
2009-01-13 · TA获得超过625个赞
知道大有可为答主
回答量:1346
采纳率:0%
帮助的人:1211万
展开全部
找到每个窗体的句柄.
sendMessage(句柄,wm_char,wparam,lparam);

面向对象 就是要 communication with message.
哈哈
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式