Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2004.09.19;
Скачать: CL | DM;

Вниз

Аналог KeyPressed() в Console Application...   Найти похожие ветки 

 
Jolik   (2004-08-04 15:23) [0]

Здравствуйте!
Вот раньше было время цикл программы состоял из:

if not KeyPressed then begin
...
end;

Как бы такой сделать в консольном приложении под Дельфями?
Спасибо!


 
Юрий Зотов ©   (2004-08-04 16:02) [1]

Посмотрите описание ReadConsoleInput. Там в конце есть такое примечание:

Remarks

If the number of records requested in the nLength parameter exceeds the number of records available in the buffer, the number available is read. The function does not return until at least one input record has been read.

A process can specify a console input buffer handle in one of the wait functions to determine when there is unread console input. When the input buffer is not empty, the state of a console input buffer handle is signaled.

==================================================

Вот и целых два ответа на Ваш вопрос. Выбирайте более подходящий.


 
Jolik   (2004-08-05 13:29) [2]

Спасибо!


 
Jolik   (2004-08-05 14:56) [3]

а где взять HANDLE hConsoleInput для передачи в функцию?


 
Игорь Шевченко ©   (2004-08-05 16:54) [4]


> а где взять HANDLE hConsoleInput для передачи в функцию?


GetStdHandle (STD_INPUT_HANDLE) ?


 
Jolik   (2004-08-05 17:27) [5]

Спасибо, попробую!


 
Jolik   (2004-08-05 20:46) [6]

Если кому интересно - ниже консольный аналог Win32 для DOS програм типа

while not KeyPressed then begin
...
end;

ЗЫ: Исходный текст на С содрал в инете - каюсь :((( Ссылку потерял - если вдруг хозяин объявится :)))



uses Windows
 // переменные поддержки чтения с клавиатуры в консольном приложении
 ir                    : INPUT_RECORD;
 hCon                  : THandle;
 NumOfEvents           : Cardinal;
 NumOfEventsRead       : Cardinal;
 i                     : integer;
 done                  : boolean;

begin
 try
   writeln("Press Esc to Exit.");

   done := FALSE;

(********* основной цикл работы (до нажатия ESC) **************)

   while (not done) do begin

     // читаем Windows сообщения нашему приложению
     if not GetNumberOfConsoleInputEvents(hCon, NumOfEvents) then
       raise EInOutError.CreateFmt(
        "GetNumberOfConsoleInputEvents failed %s", [SysErrorMessage(GetLastError)]);

     // перебираем в поисках наджатия ESC
     for i := 0 to NumOfEvents-1 do begin
       if (not ReadConsoleInput(hCon, ir, 1, NumOfEventsRead)) then
         raise EInOutError.CreateFmt(
          "ReadConsoleInput failed %s", [SysErrorMessage(GetLastError)]);

       if (NumOfEventsRead = 1) then
         done := (ir.EventType = KEY_EVENT) and
                 ir.Event.KeyEvent.bKeyDown and
                 (ir.Event.KeyEvent.wVirtualKeyCode = VK_ESCAPE);
     end;
   end;

 except
   on E : Exception do begin
     writeln(Format("Exception: %s", [E.Message]));
   end;
 end;




Страницы: 1 вся ветка

Текущий архив: 2004.09.19;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.063 c
1-1094283614
mega
2004-09-04 11:40
2004.09.19
PopUpMenu в MainMenu


14-1093917347
Думкин
2004-08-31 05:55
2004.09.19
С днем рождения!


4-1091086264
DeepProg
2004-07-29 11:31
2004.09.19
Чтение с мультиметра через RS-232C


1-1094263572
O?O
2004-09-04 06:06
2004.09.19
Адрес E.Mail


3-1092911428
Zif
2004-08-19 14:30
2004.09.19
Подкажите как загрузить JPG в Access через ADOQuery