hello guys,
i know you all are familiar with DOSCOMMAND to run a console and catch its output ..
but what if i want to send a PAUSE keystroke to the console ??

with SENDLINE i can send string and char
but how do i send a PAUSE or ENTER(RETURN) key ???

please any help ???
thank you

Dani AI

Generated

Short summary tied to the posts by and : there are two reliable approaches depending on how the console program reads input. If the target process reads from standard input (ReadLn/scanf/fgets) you can write CR/LF into its stdin. If it waits for raw key events (kbhit/getch/ReadConsoleInput) you must inject console key events (KEY_EVENT) into that process's console. "Pause" is a real key (VK_PAUSE), not a printable character; Enter is CR/LF.

If the child process uses stdin redirection, create a pipe for its stdin and write CR/LF (or the exact bytes the program expects). Example (Delphi/FPC-style outline):

var
  sa: TSecurityAttributes;
  childRd, childWr: THandle;
  si: TStartupInfo;
  pi: TProcessInformation;
  written: DWORD;
begin
  sa.nLength := SizeOf(sa);
  sa.bInheritHandle := TRUE;
  sa.lpSecurityDescriptor := nil;

  CreatePipe(childRd, childWr, @sa, 0);
  SetHandleInformation(childWr, HANDLE_FLAG_INHERIT, 0);

  ZeroMemory(@si, SizeOf(si));
  si.cb := SizeOf(si);
  si.dwFlags := STARTF_USESTDHANDLES;
  si.hStdInput := childRd;

  CreateProcess(nil, PChar('program.exe'), nil, nil, TRUE, 0, nil, nil, si, pi);

  CloseHandle(childRd);
  WriteFile(childWr, PChar(#13#10)^, 2, written, nil); // send Enter
  CloseHandle(childWr);
end;

If the program reads raw console events you must attach to its console and call WriteConsoleInput with KEY_EVENT records (send key-down then key-up). Minimal outline:

var
  pid: DWORD;
  hIn: THandle;
  rec: TInputRecord;
  written: DWORD;
begin
  if AttachConsole(pid) then
  begin
    hIn := GetStdHandle(STD_INPUT_HANDLE);
    FillChar(rec, SizeOf(rec), 0);
    rec.EventType := KEY_EVENT;
    rec.KeyEvent.bKeyDown := TRUE;
    rec.KeyEvent.wVirtualKeyCode := VK_RETURN; // or VK_PAUSE
    rec.KeyEvent.UnicodeChar := #13;
    WriteConsoleInput(hIn, @rec, 1, written);
    rec.KeyEvent.bKeyDown := FALSE;
    WriteConsoleInput(hIn, @rec, 1, written);
    FreeConsole;
  end;
end;

Notes and cautions: make sure handle inheritance flags, CreateProcess bInheritHandles and SetHandleInformation are correct; CR vs CRLF depends on the target; AttachConsole/WriteConsoleInput only works in the same session and may fail across integrity/elevation boundaries; SendInput/SendKeys to background windows is unreliable. If your DOSCOMMAND wrapper already redirects stdin, try sending #13 or #13#10 first — otherwise use the console-event approach shown above.

Sorry but no Pascal I used had such a thing as DOSCOMMAND. I would be guessing what Pascal this is so for now I'll write you need to be complete in your details. Not everyone can guess what you have for the dev system.

That said, I just had to work a very very old app and in VB6 the old SendKeys() is dead now. It wasn't a big deal as what I needed to do was possible another way. But that's only to highlight that Windows (are you using Windows?) may start to block such as time goes on for security reasons.

If you are using a script or shelling out to DOS or CMD, then maybe what you are trying to automate could be done with AUTOIT?
https://forum.lazarus.freepascal.org/index.php?topic=4297.0 kicks this around and I see a reply with the Windows and Linux API calls.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.