1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| {oct 2004 : testé ok si SetForegroundWindow(ParentHwnd); en rem}
procedure SendKeys(WinHandle:Hwnd;Buffer:String);
var
I: Integer;
W: Word;
D: DWORD;
P: ^DWORD;
begin
P:=@D;
SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT,0,P,0);
if IsIconic(WinHandle) then
ShowWindow(WinHandle,SW_RESTORE);
SetForegroundWindow(WinHandle);
For I := 1 to Length(Buffer) do
begin
W := VkKeyScan(Buffer[i]);
keybd_event(w,0,0,0);
keybd_event(w,0,KEYEVENTF_KEYUP,0);
end;
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,0,nil,0);
//SetForegroundWindow(ParentHwnd);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,D,nil,0);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
WinExec('notepad.exe', SW_NORMAL);
SendKeys(FindWindowEx(FindWindow('Notepad', 'Untitled - Notepad'), 0, 'Edit', ''), 'Your Text Here');
end; |
Partager