Created
December 29, 2023 07:39
-
-
Save technoscavenger/71865791bf44cb0eaa421d27c5ae6ed2 to your computer and use it in GitHub Desktop.
Delphi: Waiting for ESCAPE key before continuing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program Project4; | |
{$APPTYPE CONSOLE} | |
{$R *.res} | |
uses | |
System.SysUtils, | |
Winapi.Windows; | |
procedure WaitForEscapeKey; | |
var | |
Done: Boolean; | |
Event: TInputRecord; | |
EventsRead: DWORD; | |
begin | |
Done := False; | |
repeat | |
ReadConsoleInput(GetStdhandle(STD_INPUT_HANDLE), | |
Event, 1, EventsRead); | |
if Event.Eventtype = key_Event then begin | |
if Event.Event.KeyEvent.bKeyDown then | |
begin | |
Done := Event.Event.KeyEvent.wVirtualKeyCode = VK_ESCAPE; | |
if (not Done) and (Event.Event.KeyEvent.AsciiChar <> #0) then | |
begin | |
WriteLn('You typed: ', Event.Event.KeyEvent.AsciiChar, ' - waiting for ESC'); | |
Sleep(50); | |
end; | |
end; | |
end; | |
until Done; | |
end; | |
begin | |
try | |
Writeln('Press escape to end'); | |
WaitForEscapeKey; | |
except | |
on E: Exception do | |
Writeln(E.ClassName, ': ', E.Message); | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment