function IsOnConsole: Boolean; stdcall;
var
sbi: TConsoleScreenBufferInfo;
h: THandle;
begin
h := GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(h, sbi);
Result := not (sbi.dwCursorPosition.X > 0) and (sbi.dwCursorPosition.Y > 0);
end;
function EnableEcho(const Enable: Boolean): Cardinal; stdcall;
var
StdHandle: THandle;
begin
StdHandle := GetStdHandle(STD_INPUT_HANDLE);
if StdHandle = INVALID_HANDLE_VALUE then Exit;
GetConsoleMode(StdHandle, Result);
if Enable then
SetConsoleMode(StdHandle, Result or ENABLE_ECHO_INPUT)
else
SetConsoleMode(StdHandle, Result and not ENABLE_ECHO_INPUT);
end;
procedure ClearScreen;
var
sbi: TConsoleScreenBufferInfo;
h: hwnd;
Cord: _COORD;
R: Cardinal;
begin
h := GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(h, sbi);
Cord.X := 0;
Cord.Y := 0;
FillConsoleOutputCharacter(h, ' ', sbi.dwSize.X * sbi.dwSize.Y, Cord, R);
SetConsoleCursorPosition(h, Cord);
end;
function KeyPressed: Char;
var
Console: Cardinal;
OldMode: Cardinal;
BufferSize: Cardinal;
begin
Console := GetStdHandle(STD_INPUT_HANDLE);
GetConsoleMode(Console, OldMode);
SetConsoleMode(Console, OldMode and not (ENABLE_LINE_INPUT or ENABLE_ECHO_INPUT));
ReadConsole(Console, @Result, 1, BufferSize, nil);
SetConsoleMode(Console, OldMode);
end;
procedure PressAnyKey;
const
PressAnyKey = 'Press any key to continue...';
var
BufferSize: Cardinal;
begin
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), PChar(PressAnyKey),Length(PressAnyKey), BufferSize, nil);
KeyPressed;
end;
procedure GotoXY(X, Y: Word);
var
Coord: _COORD;
begin
Coord.X := X;
Coord.Y := Y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Coord);
end;
function WhereXY: TCoord;
var
Info: _CONSOLE_SCREEN_BUFFER_INFO;
begin
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), Info);
Result := Info.dwCursorPosition;
end;
function WhereX: SmallInt;
begin
Result := WhereXY.X;
end;
function WhereY: SmallInt;
begin
Result := WhereXY.Y;
end;
function SetColor(Color: Word): DWORD;
var
Info: CONSOLE_SCREEN_BUFFER_INFO;
begin
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), Info);
Result := Info.wAttributes;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), Info.wAttributes or Color);
end;