大悟还俗

邮箱 key_ok@qq.com 我的收集 http://pan.baidu.com/share/home?uk=1177427271
  新随笔  :: 联系 :: 订阅 订阅  :: 管理

Console下Pause效果的函数

Posted on 2013-10-21 13:36  大悟还俗_2  阅读(687)  评论(0编辑  收藏  举报

function PauseConsole(Prompt: PAnsiChar): boolean;
var
  hStdIn, hStdOut: THandle;
  dwRd, dwWr, i: Cardinal;
  cBuf: array [0..128] of TInputRecord;
begin
  result := false;
  hStdIn := GetStdHandle(STD_INPUT_HANDLE);
  hStdOut := GetStdHandle(STD_OUTPUT_HANDLE);
  if ((hStdIn <> 0) and (hStdOut <> 0)) then
  begin
     WriteFile(hStdOut,Prompt[0],lstrlenA(Prompt),dwWr,nil);
     while ReadConsoleInput(hStdIn,cBuf[0],128,dwRd) do
     begin
       for i := 0 to dwRd do
       begin
         if ((cBuf[i].EventType = KEY_EVENT) and (cBuf[i].Event.KeyEvent.bKeyDown)) then
         begin
           Result := true;
           exit;
         end;
       end;
     end;
  end;
end;

 

 

  try
    PauseConsole('Press a key to continue...');
  except
    on E:Exception do
      Writeln(E.Classname, ': ', E.Message);
  end;