Posted by Frank Crenshaw on February 21, 2007
In Reply to reading single char from standard input posted by Andre Lamothe on
February 11, 2007
How do i read a single char from standard input... read(c) is blocking until enter
is pressed, i don't want that, i need a single char immedietly. Can i connect somehow TFileStream with
standard input?
Please help
This is a very simple console program.
This will read and write characters to and from standard io until a carriage
return is entered - then it will terminate.
Obviously you can add much more functionality to it to look for various arrow keys, tabs, spaces -ect.
hope that helps
program Project1; {$APPTYPE CONSOLE} uses SysUtils; var ch: char; done: boolean; function scanchar(ch: char): boolean; begin read(ch); result := (ch = #13) or (ch = #10); end; begin done := false; while not done do begin done := scanchar(ch); if not done then write(ch); end; end.
Related articles