How can I get Delphi to pass F4 to the input pipe to a CMD process? I've been using code which is very similar to the answer here: Pipes in Delphi for Command Prompt
For simpliity I have only 4 objects on the form: 1. CommandText (a TMemo which displays a representation of the CMD window). 2. CommandRun (a TEdit where the CMD line to be run is entered). 3. SendBtn (a TButton used to send CommandRun.Text to CMD). 3. ExitBtn (a TButton used to exit the program).
Here are my Write Pipe and Send procedures:
Write Pipe
procedure WritePipeOut(OutputPipe: THandle; InString: string);
// writes Instring to the pipe handle described by OutputPipe
var
byteswritten: DWord;
AnsiBuf: AnsiString;
begin
// most console programs require CR/LF after their input.
if InString = 'f4' then AnsiBuf := #113#13#10
else AnsiBuf := AnsiString(InString) + #13#10;
WriteFile(InputPipeWrite, AnsiBuf[1], Length(AnsiBuf), byteswritten, nil);
end;
Send
procedure TForm1.SendBtnClick(Sender: TObject);
begin
WritePipeOut(OutputPipeWrite, CommandRun.Text);
CommandRun.Text := '';
CommandRun.SetFocus;
end;
Commands like DIR are passing through properly and the results are successfully being 'echoed' to CommandText. My problem is that I am launching a program via the pipe. In a normal CMD window the program can only be stopped by pressing the F4 key. I need to replicate this F4 press via the pipe and just cannot work out how to achieve this. I would be very grateful for any guidance.