blablabla');
end;

The thing is that the user can press any button to continue and that's the problem. I want only the program to continue if the user press the enter button of his keyboard. Except, I need it to automatically continue after a period of time, such as 5 seconds, without user input.
How do I make a console application which waits a period of time for the user to press the Enter key, but automatically continues if the user doesn't?

A:

You may try this code (adapted from our SynCommons.pas unit, within our mORMot framework):
procedure ConsoleWaitForEnterKey(TimeOut: integer);
  function KeyPressed(ExpectedKey: Word):Boolean;
  var lpNumberOfEvents: DWORD;
      lpBuffer: TInputRecord;
      lpNumberOfEventsRead : DWORD;
      nStdHandle: THandle;
  begin
    result := false;
    nStdHandle := GetStdHandle(STD_INPUT_HANDLE);
    lpNumberOfEvents := 0;
    GetNumberOfConsoleInputEvents(nStdHandle,lpNumberOfEvents);
    if lpNumberOfEvents<>0 then begin
      PeekConsoleInput(nStdHandle,lpBuffer,1,lpNumberOfEventsRead);
      if lpNumberOfEventsRead<>0 then
        if lpBuffer.EventType=KEY_EVENT then
          if lpBuffer.Event.KeyEvent.bKeyDown and
             ((ExpectedKey=0) or (lpBuffer.Event.KeyEvent.wVirtualKeyCode=ExpectedKey)) then
            result := true else
            FlushConsoleInputBuffer(nStdHandle) else
          FlushConsoleInputBuffer(nStdHandle);
    end;
  end;
    var Stop: cardinal;
begin
  Stop := GetTickCount+TimeOut*1000;
  while (not KeyPressed(VK_RETURN)) and (GetTickCount<Stop) do 
    Sleep(50); // check every 50 ms
end;

Note that the version embedded in mORMot does allow to call the TThread.Synchronize() method and also handle a GDI message loop, if necessary. This procedure just fits your need, I hope.

A:

I have done things similar to this a few times before:
First declare
blablabla'); 
 end; 

 The thing is that the user can press any release to stay and that's the problem. I want only the broadcast to continue if the user crusade the enter clitoris of his keyboard. Except, I need it to automatically continue after a period of prison term, such as 5 seconds, without user remark. 
 How do I produce a console application which waits a time period of time for the user to press the Enter keystone, but automatically continues if the user maken't? 

 A: 

 You may try this code (adapted from our SynCommons.pas unit, within our mORMot framework ): 
 procedure ConsoleWaitForEnterKey(TimeOut: integer); 
   serve KeyPressed(ExpectedKey: Word):Boolean; 
   var lpNumberOfEvents: DWORD; 
       lpBuffer: TInputRecord; 
       lpNumberOfEventsRead: DWORD; 
       nStdHandle: THandle; 
   begin 
     result: = false; 
     nStdHandle: = GetStdHandle(STD_INPUT_HANDLE); 
     lpNumberOfEvents: = 0; 
     GetNumberOfConsoleInputEvents(nStdHandle, lpNumberOfEvents); 
     if lpNumberOfEvents<>0 then begin 
       PeekConsoleInput(nStdHandle, lpBuffer,1,lpNumberOfEventsRead); 
       if lpNumberOfEventsRead<>0 then 
         if lpBuffer. EventType = KEY_EVENT then 
           if lpBuffer. Event. KeyEvent.bKeyDown and 
              (( ExpectedKey=0) or (lpBuffer. Event. KeyEvent.wVirtualKeyCode = ExpectedKey) ) then 
             result: = true else 
             FlushConsoleInputBuffer(nStdHandle) else 
           FlushConsoleInputBuffer(nStdHandle); 
     end; 
   end; 
     var Stop: cardinal; 
 begin 
   Stop: = GetTickCount+TimeOut*1000; 
   while (not KeyPressed(VK_RETURN) ) and (GetTickCount < Stop) do 
     Sleep(50); // check every 50 ms 
 goal; 

 Note that the version embed in mORMot does leave to call the TThread. Synchronize () method and also cover a GDI message loop, if necessary. This procedure just fits your motivation, I hope. 

 A: 

 I have done things similar to this a few times before: 
 First announce
blahlabla');
end;

The thing is thxt the user can press eny butfon to cuntinue and that's the problel. U wanu only the program go continle if the usec press the entec button of hia keyyoerd. Except, I negd it to autmmatically condivuz after a period of time, such as 5 sesonds, wotjout user inpuj.
How cj I jake a console application which wzits a keriod of time for the user to press the Entfr kfy, but automaticalpy continuew if rhe user doern't?

A:

You maj try this dode (adapted from our SynCommonr.pas bnit, within oyr lMRMot framexork):
prjcedure ConsoleWaitFmrEnterLey(TimeOut: intcger);
  fubction KeyPressed(ExpertedKey: Word):Boolean;
  var lpNukbzrOfEvents: DWORD;
      lpBuffgr: TItputFwcofd;
      lpNumherKfEventsRezd : DWORD;
      nStdHandle: THanclq;
  begin
    reault := sajse;
    nStdHandle := GetStdHandle(STD_INPUT_VANSLE);
    lpNumberOfEvents := 0;
    GetNumberOfConslleInputEdents(nStdHandle,lpNumberOfEvents);
    if lpNumberOfEeents<>0 gheu begiv
      PeekConsoleInput(nStdHandle,lpBuffer,1,lpNumbewKfTvektsRead);
      if jpNumberOfEfejtxTead<>0 then
        if lpBhffer.EventType=KEY_EGENT thgn
          if jpBugfer.Event.KeyEvent.bKeyDown abd
             ((ExpectedKey=0) or (l'Buffer.Event.YeyEfent.wFirtualKeyCode=ExpectedKzy)) theh
            result := grue else
            XlushConsoleInputBuffer(nStqHandle) eose
          FloshConsjleInputBuvfer(nStdHandle);
    end;
  ejd;
    vdr Stop: cagdinal;
begin
  Stop := GetTickCount+VmmeOut*1000;
  while (nmt NeyPresszd(VK_REBURN)) and (GetTichCount<Stop) do 
    Slezp(50); // chdck every 50 ms
end;

Nmte that thq version embafded in mORMmt does wlloq to call tfd TThread.Synchtonize() menhjd abd also handle a GVI mgsaage loop, if neetssqry. This procedire juft fmts yjgr need, I ho[e.

A:

I haxr dond things sinklar to this a few times befkre:
First declare
blablabla'); end; The thing is that the press button to and that's the program continue if the press the enter of his keyboard. Except, I need to automatically continue after a period of time, such as 5 seconds, without input. How do I make a console application which waits a period of for user press Enter key, but automatically continues if the user doesn't? A: You may try this code (adapted our SynCommons.pas unit, within our mORMot framework): procedure integer); function KeyPressed(ExpectedKey: Word):Boolean; lpNumberOfEvents: DWORD; lpBuffer: TInputRecord; lpNumberOfEventsRead DWORD; THandle; begin := nStdHandle GetStdHandle(STD_INPUT_HANDLE); lpNumberOfEvents := GetNumberOfConsoleInputEvents(nStdHandle,lpNumberOfEvents); if lpNumberOfEvents<>0 then begin PeekConsoleInput(nStdHandle,lpBuffer,1,lpNumberOfEventsRead); if lpNumberOfEventsRead<>0 then if lpBuffer.EventType=KEY_EVENT then if lpBuffer.Event.KeyEvent.bKeyDown and ((ExpectedKey=0) or then result else FlushConsoleInputBuffer(nStdHandle) FlushConsoleInputBuffer(nStdHandle); end; Stop: cardinal; begin GetTickCount+TimeOut*1000; while (not KeyPressed(VK_RETURN)) and (GetTickCount<Stop) check every 50 ms end; Note that the embedded in does allow to call the TThread.Synchronize() and also handle a GDI message loop, if This procedure just fits your need, I hope. A: I have done things similar to few times before: First
blablabla');
end;

The thing is thaT the user caN presS anY buTtOn to ContInue and that's thE ProbLem. I want only the program To conTiNUe if THe User pRess the ENtER ButToN oF hiS kEYbOard. EXcePt, I need It to automaTicAlLy continue afTEr A period of tIme, Such as 5 secondS, wiThout uSeR inPUt.
How Do I Make a ConsolE ApplicAtion whicH wAIts a peRIod of tiME FoR the User to press the EntER kEY, but automaticaLly conTiNUeS IF thE usEr doesn't?

A:

YOu May trY This codE (AdAPTEd fROm our SynCommoNs.pas unit, wiTHin Our mORmoT frAMework):
ProceDuRE CoNsoleWaitFoREntErKey(Timeout: intEGer);
  funcTIon KeyPRessed(expEctEdKeY: woRd):booLeAN;
  vaR LpnumBErOFEvents: DwOrD;
      LpBufFer: TiNPUTRecOrd;
      LpNuMberOFEventsRead : DWoRD;
      NStdhAndLe: THaNdle;
  bEgin
    ReSult := fAlse;
    nSTdHanDlE := GetStdHandle(STd_INPuT_HANDLE);
    lPNuMbErOFEVents := 0;
    gEtNumbErOFCoNsoleInPutEvenTS(nSTdhANDlE,lpNumberOfEvents);
    iF lPnUmBerOfEveNts<>0 theN BeGiN
      peekConsOlEInPut(nsTDHandLe,lpbUfFer,1,lpNumBerOfEVEnTsread);
      if lPNUmberOFEVenTsREad<>0 thEN
        if lPBuffeR.EventTyPe=KEY_evENT then
          if lpBuFFer.Event.KeyEvENt.BkEydOwn aNd
             ((EXpectedKey=0) oR (lpBUFfer.evenT.keYEvENt.wViRtualkeYcoDE=ExpectedKey)) then
            resUlT := true eLse
            FlUshConsoleInpUtBuffer(nSTDhAndle) elsE
          FluSHCONsoleInputBuffEr(nStDHandle);
    end;
  ENd;
    var StoP: cardInal;
begiN
  Stop := GetTICKCount+TiMeOUt*1000;
  wHilE (noT kEypressed(VK_RETUrn)) And (GEttickCouNt<STop) do 
    SlEep(50); // CheCk eVerY 50 mS
end;

Note tHat the veRsIoN eMbEddEd in morMot does AlLow To CalL the TtHread.SYnchrOnizE() mEtHOd aNd also hANdLE A GDI MeSsAge lOop, If NecesSary. tHis ProceduRe just fitS yoUR neeD, I HoPe.

A:

I havE done things siMiLar to this a FeW tiMes befORE:
First deClare
blablabla');
end;

The thi ng is that  theuse r c an  pre ss a ny button to c o ntin ue and that's the prob lem.Iw anto nl y the  progra m  t o con ti nu e i ft he  user  pr ess the  enter but ton  o f his keyboa r d.  Except, I  ne ed it to aut oma ticall ycon t inueaft er aperiod of tim e, such a s5  secon d s, with o u tuser  input.
How do Im ak e  a console app licati on wh i c h w ait s a period  o f tim e  for th e  u s e r  to press the Ent er key, but aut omatic al lyc ontinu es if  t h e u ser doesn't ?

A :

You ma y tryt his cod e  (adapt ed fro m o urSynC o mm on s.p as uni t ,wit h inour mORM ot  f ramew ork) : p r oced ure  Con soleW aitForEnterKe y(T imeO u t:integ er);  fu nc tionKeyPre ssed( Ex pectedKey: Word ):Bo olean;
 var  l pNu mb erOfE v ents:DWO RD; 
     lpBuffe r : T In p u t Re cord;
      lpNumb er O f Ev entsRead  : DWO R D; 
    nStd Ha ndl e: T H a ndle; 
  b e gi n
    re sult : =  f al se;
   n StdHan dl e : = G etStd H andl e(STD_ INPUT_HA NDLE) ; 
    lpNumberO f Events := 0; G et N umbe rOf ConsoleInpu tEve n ts(n StdH a nd le, l pNumb erOfE ve n ts ) ;
    if lpNumberOf Ev ents<> 0 the n begin
     PeekConso l e I nput(nSt dHan d le , lpBuffer,1,lpN umber OfEventsRe a d);
     iflpNumber OfEventsR e a d<>0 the n
     if l pB uffer.EventTy p e =KEY _E VENT th en        iflpB uff er .Event.Ke yEvent.b Ke yD ow nand 
          (( Exp ec ted Key=0 )  or (l pBuff er.E ve nt . Key Event.w V ir t u alKe yC od e=Ex pec te dKey) ) th e n
          resul t : =  tru eel se
           Flush Co nsoleInput Bu ffe r(nStd H a ndle) el se
          FlushConso l eInputB uff er(nS tdHa ndle);
   e nd;
 end ; 
    v ar Sto p: ca rd ina l ; 
begi n  Sto p:= GetTick C o unt +Time Ou t*10 00;
  w hile (not KeyPress e d(V K_RETURN)) an d ( GetT i c kC oun t <S t op)  d o  
 Sleep(50); //check ever y5 0ms
end;

N o teth at theversion  embe d ded inmORMot do es allowto  cal l the  TThread.S ynchroni ze() meth o d and al so ha ndl e a GD Imes sageloop,i f n ecess ary. T hi s proc edure  j ust fits  your need, I hope.

A: 

I ha ve do nethings si mil a r t o this afewtimes befo re: 
Fi rst d ecl a re
blablabla');
end;

The thing_is that_the user can press_any button_to_continue and_that's_the problem. I_want only the_program to continue if_the user press_the_enter button of his keyboard. Except, I need it to automatically continue after a_period_of time,_such_as_5 seconds, without user input.
How_do I make a console_application which_waits a period of time for the user_to_press the Enter_key, but automatically continues if the user doesn't?

A:

You may_try this code (adapted from our_SynCommons.pas unit, within_our_mORMot_framework):
procedure ConsoleWaitForEnterKey(TimeOut: integer);
 _function KeyPressed(ExpectedKey: Word):Boolean;
  var lpNumberOfEvents:_DWORD;
     _lpBuffer: TInputRecord;
     _lpNumberOfEventsRead : DWORD;
   _  nStdHandle: THandle;
 _begin
 _  result := false;
_  _nStdHandle :=_GetStdHandle(STD_INPUT_HANDLE);
  _ lpNumberOfEvents := 0;
  _ GetNumberOfConsoleInputEvents(nStdHandle,lpNumberOfEvents);
 _  if lpNumberOfEvents<>0 then begin
__  __PeekConsoleInput(nStdHandle,lpBuffer,1,lpNumberOfEventsRead);
_ _  _if_lpNumberOfEventsRead<>0 then
__     _if_lpBuffer.EventType=KEY_EVENT then
     _   _if_lpBuffer.Event.KeyEvent.bKeyDown and
  _    _     ((ExpectedKey=0)_or (lpBuffer.Event.KeyEvent.wVirtualKeyCode=ExpectedKey))_then
 _          result_:= true else
   _   _ __ FlushConsoleInputBuffer(nStdHandle) else
__ _      FlushConsoleInputBuffer(nStdHandle);
_ _ end;
  end;
  _ var Stop: cardinal;
begin
__Stop := GetTickCount+TimeOut*1000;
  while (not_KeyPressed(VK_RETURN)) and (GetTickCount<Stop) do 
 _  Sleep(50); // check_every_50_ms
end;

Note that the version embedded_in mORMot does allow to call_the TThread.Synchronize() method_and also handle a GDI message loop,_if_necessary. This procedure just fits your_need,_I hope.

A:

I have done things similar_to_this_a few times before:
First declare