function Keypressed: Boolean; var InputBuffer: THandle; InputRecord: INPUT_RECORD; Count: Cardinal; begin Result:= FALSE; InputBuffer:= GetStdHandle(STD_INPUT_HANDLE); if InputBuffer <> INVALID_HANDLE_VALUE then if PeekConsoleInput(InputBuffer,InputRecord,1,Count)and (Count = 1) then begin if InputRecord.EventType = KEY_EVENT then if TKeyEventRecord(InputRecord.Event).bKeyDown then begin Result:= TRUE; Exit; end; ReadConsoleInput(InputBuffer,InputRecord,1,Count) end; end; function Readkey: Char; var InputBuffer: THandle; InputRecord: INPUT_RECORD; Count: Cardinal; begin Result:= #0; InputBuffer:= GetStdHandle(STD_INPUT_HANDLE); if InputBuffer <> INVALID_HANDLE_VALUE then while ReadConsoleInput(InputBuffer,InputRecord,1,Count) do if InputRecord.EventType = KEY_EVENT then if TKeyEventRecord(InputRecord.Event).bKeyDown then begin Result:= TKeyEventRecord(InputRecord.Event).AsciiChar; Exit; end; end;
Ejemplos de uso:
repeat Sleep(10); until Keypressed;
Writeln('Pulsa una tecla ...'); Writeln('Has pulsado la tecla: ' + ReadKey);
repeat Sleep(10); until Keypressed; Writeln('Has salido de bucle con la tecla: ' + ReadKey);
procedure Pause; begin Writeln('Pulse una tecla para continuar ...'); ReadKey; end;
var C: Char; begin repeat Writeln; Writeln('[1] Pulsa 1'); Writeln('[2] Pulsa 2'); Writeln; Write('Escoge una opcion: '); C:= Readkey; until C in ['1','2']; Writeln; Writeln('Has escogido: ' + C); end;
Saludos
PD: escafandra ahora te toca a ti