PDA

View Full Version : Nonblocking standard input



{MSX}
25-09-2007, 10:00 AM
Hi! Is there a way to read from standard input with a nonblocking call? That is, the call should return even if there is no data..
Or eventually a way to see if there is data avaiable on standard input..

Thanks :P

JSoftware
25-09-2007, 11:31 AM
You might be able to poll the keyboard input buffers. This would be nonblocking

{MSX}
25-09-2007, 02:16 PM
ok.. but how do you do it? :)
also, is this way cross platform?

thanks :)

JSoftware
25-09-2007, 03:11 PM
function readKeydownCount: integer;
var a: array[0..63] of TInputRecord;
vb: cardinal;
I: Integer;
t: TKeyEventRecord;
begin
result := 0;
PeekConsoleInput(GetStdHandle(STD_INPUT_HANDLE), a[0], 64, vb);
for I := 0 to vb - 1 do
begin
if (a[i].EventType and KEY_EVENT) = KEY_EVENT then
begin
t := a[i].Event.KeyEvent;
if t.bKeyDown then
inc(result);
end;
end;
end;

Sorry, I don't know any crossplatform way of doing it except for reading some INT 0x10 stuff :P

marcov
28-10-2007, 12:13 PM
Pure standard input, or do you know it is always the keyboard?

(The first typically for cgi's, the second for console programs)

If the latter, have a look at the "keyboard" unit that is used by the textmode IDE. The textmode IDE needs such functionality too, since it is eventdriven.