Board index » delphi » Unbuffered keyboard input

Unbuffered keyboard input

In a Console application (D4) I found Read to return only, when a line has been
completed with Enter. How can I write an application which reacts
/immediately/, as soon as any key is pressed?

Where can I find more information about the involved objects or variables in
console applications?

Are Console-API functions applicable in Delphi console applications?

DoDi

 

Re:Unbuffered keyboard input


Try this :-

program Greeting;

Uses SysUtils, Windows ;

{$APPTYPE CONSOLE}

var
  MyMessage: string;
  S : String ;
  I : Integer ;
  H : DWORD ;
  COORD : _COORD ;
  BR : Cardinal ;
begin
  I := 1 ;
  MyMessage := 'Hello world! - CLS or EXIT to Quit';
  While I <> 0 Do
    Begin
      Writeln(MyMessage + ' ' + IntToStr(I) );
      I := I + 1 ;
      //Readln( S ) ;
      H := GetStdHandle( STD_INPUT_HANDLE ) ;
      SetConsoleMode( H, 0 ) ;
      S := 'x' ;
      ReadConsole( H, @S[1], 1, BR, Nil );
      //
      S := UpperCase( S ) ;
      WriteLn( S + 'x' + IntToStr( BR ) );
      If S = 'EXIT' Then
         I := 0 ;
      If S = 'CLS' Then
         Begin
         H := GetStdHandle( STD_OUTPUT_HANDLE ) ;
         COORD.X := 0 ;
         COORD.Y := 0 ;
         SetConsoleCursorPosition( H, COORD);
         S := StringOfChar( Chr(32), 2000 ) ;
         Writeln( S ) ;
         SetConsoleCursorPosition( H, COORD);
         End;
    End;
end.

On 06 Jan 2002 00:45:53 GMT, vb...@aol.com (VBDis) wrote:

Quote
>In a Console application (D4) I found Read to return only, when a line has been
>completed with Enter. How can I write an application which reacts
>/immediately/, as soon as any key is pressed?

>Where can I find more information about the involved objects or variables in
>console applications?

>Are Console-API functions applicable in Delphi console applications?

>DoDi

Re:Unbuffered keyboard input


Im Artikel <3c381910.5155...@news.u-net.com>, je...@iss.u-net.com (J French)
schreibt:

Quote
>Try this :-

Thanks, I'll give it a try. In the meantime I also found that a BCB console
application allows to use the old getch etc. functions, which are not available
in Delphi.

DoDi

Other Threads