How do I check if another application is busy?
I have a program that sends text to a console. The text that I will send contains #13 char (i.e. ls#13cd documents#13dir
). In other words I want to send many commands at one time and the console will process it one by one. I am sending it character by character. But sometimes it only executes ls
and cd documents
. I think maybe this is because it continuously sends character even if the console is still busy and for that, it didn't receive the incoming character. This is my code:
procedure TForm1.SendTextToAppO(Str: String; AHandle: Integer);
var
iWindow, iPoint, i: Integer;
SPass: PChar;
sList: TStringList;
begin
sList := TStringList.Create;
ExtractStrings([#13],[' '],PChar(Str),sList);
iWindow := AHandle;// AHandle is the handle of the console
iPoint := ChildWindowFromPoint(iWindow, Point(50,50));
for i:=0 to sList.Count-1 do begin
SPass := PChar(sList[i]);
try
while(SPass^ <> #$00) do begin
SendMessage(iPoint,WM_CHAR,Ord(SPass^),0);
Inc(SPass);
end;
SendMessage(iPoint,WM_KEYDOWN,VK_RETURN,0);
except
// do nothing;
end;
end;
end;
Please let me know if you did not understand my question. By the way, I am using Delphi 7.