用readln或read(temp)当然能暂停,但是用户能随便乱输点什么,然后再回车结束。
我希望是如同windows or MS-DOS的控制台一样的效果——好比输入pause命令,给出的结果,或者执行 dir /p式的效果,系统提示按任意键继续;用户随便按什么键就往下走了;
c里面是直接调用console的pause命令的;
用winexec调用pause(cmd.exe /k pause),结果是在程序执行完毕方才执行pause;
用ShellExecute调用pause(cmd.exe /k pause),结果是开了一个新console(哪怕已经指定好现有console的句柄);
各位高见?

解决方案 »

  1.   

    up;
    主要是让程序看起来舒服;
    read是不行的。
    console程序总不能去拦消息?
      

  2.   

    我解决了,呵呵!我又可以有40分了
    program ReadKeyApp;{$APPTYPE CONSOLE}uses Windows, SysUtils;// ReadKey for Win32 consoletype TKeyShiftState = (kssRightAlt, kssLeftAlt,
       kssRightCtrl, kssLeftCtrl, kssShift, kssNumLock,
       kssScrollLock, kssCapsLock, kssEnhancedKey);type TKeyShiftSet = set of TKeyShiftState;type
       PKeyEventRecordFix = ^TKeyEventRecordFix;
       TKeyEventRecordFix = packed record
          bKeyDown: BOOL;
          wRepeatCount: Word;
          wVirtualKeyCode: Word;
          wVirtualScanCode: Word;
          KeyShiftState: TKeyShiftSet;
          case Integer of
     0: (
        UnicodeChar: WCHAR;
        dwControlKeyState: DWORD);  // Fix an error in Windows.pas
     1: (
        AsciiChar: CHAR)
       end;var
       VirtualKeyCode: Word;
       VirtualScanCode: Word;{
      This function checks whether we are interested in this particular
      keypress - we want to ignore Shift,Alt,Ctrl and the ??-Lock keys.  Use the KeyShiftState field to test for whether anyone is pressing
      these keys ...
    }
    function VetoOnVKCode(const VKCode: Word): Boolean;
    const
      NumVetoKeys = 6;
      VetoKey: array[1..NumVetoKeys] of Word = (VK_CONTROL, VK_SHIFT,
        VK_MENU, VK_CAPITAL,
        VK_NUMLOCK, VK_SCROLL);
    var
      iKey: Integer;
    begin
       for iKey := 1 to NumVetoKeys do
          if VKCode = VetoKey[iKey] then
          begin
     Result := True;
     Exit
          end;
       Result := False
    end;function ReadKey: Char;
    var
       NumRead:   Cardinal;
       HConsoleInput: THandle;
       InputRec:   TInputRecord;
    begin
    {
      Get Input-handle for the console ...
    }
       HConsoleInput := GetStdHandle(STD_INPUT_HANDLE);
    {
      Put thread to sleep until Console-Input is available- don't waste CPU
      cycles deadlocking the machine ...
    }
       repeat
          if WaitForSingleObject(HConsoleInput,INFINITE) <>
     WAIT_OBJECT_0 then
     raise Exception.Create('Invalid handle for console input');
    // Input buffer destroyed during Wait
          if ReadConsoleInput(HConsoleInput,
    InputRec,
    1,
    NumRead) and
     (InputRec.EventType = KEY_EVENT) then
          begin
     with PKeyEventRecordFix(@InputRec.Event.KeyEvent)^ do
     if bKeyDown and   // Input buffer contains key-presses AND
       // key-releases. We only want the presses.
        not VetoOnVKCode(wVirtualKeyCode) then
     begin
        VirtualScanCode := wVirtualScanCode;
        VirtualKeyCode := wVirtualKeyCode;
        KeyShiftState := TKeyShiftSet(LongRec(dwControlKeyState).Lo);
        Result := AsciiChar;
        Exit;
     end;
          end;
       until False;
    end;begin
      Writeln('Press any key to continue ...');
      ReadKey;
      Writeln('Press any key to Exit ...');
      ReadKey;
    end.
      

  3.   

    Great Thanks,这几天看老的csdn杂志也找到一些方法;发分。