The Console Unit
The console unit is a ready-made Pascal program that adds some useful functionality to our code.
|
You can download it here
Make sure that it is stored in the same folder as your Delphi project. Then just modify the 'Uses' line to read like this |
uses
SysUtils,console;
These are the extra commands that console makes available:
readkey : Returns a character telling you which key was pressed. If it's one of the special keys - for example the arrow key, the first character will be character(0), you then read again to find out what the extended code was.
keypressed : True or false, tells you if a key was pressed without waiting for that to happen.
LArrowPressed, RArrowPressed, UArrowPressed and DArrowPressed: Return true or false if the arrow keys have been pressed. These allow for a smoother keyboard input than using keypressed or readkey.
gotoxy(x,y) : Allows you to move the cursor to a specific coordinate on the screen
wherex and wherey : Allow you to find out where the cursor is
textcolor(c) : Will change the text foreground colour. Use either a colour name from the list 'black, blue, green, cyan, red, magenta, brown, lightgrey, darkgray, lightblue, lightgreen, lightcyan, lightred, lightmagenta, yellow, white" or use a number between 1 and 15
textbackground(c): Will change the background colour in the same way
clrscr : clears the screen
beep(frequency, duration) : beeps the computer's speaker - try beep(400,1000);
quickbeep(frequency, duration): same as beep, but doesn't pause the computer's output.
There are more, but these are the important ones. You can have a look for yourself and see how the unit works - just open it in Delphi.
readkey : Returns a character telling you which key was pressed. If it's one of the special keys - for example the arrow key, the first character will be character(0), you then read again to find out what the extended code was.
keypressed : True or false, tells you if a key was pressed without waiting for that to happen.
LArrowPressed, RArrowPressed, UArrowPressed and DArrowPressed: Return true or false if the arrow keys have been pressed. These allow for a smoother keyboard input than using keypressed or readkey.
gotoxy(x,y) : Allows you to move the cursor to a specific coordinate on the screen
wherex and wherey : Allow you to find out where the cursor is
textcolor(c) : Will change the text foreground colour. Use either a colour name from the list 'black, blue, green, cyan, red, magenta, brown, lightgrey, darkgray, lightblue, lightgreen, lightcyan, lightred, lightmagenta, yellow, white" or use a number between 1 and 15
textbackground(c): Will change the background colour in the same way
clrscr : clears the screen
beep(frequency, duration) : beeps the computer's speaker - try beep(400,1000);
quickbeep(frequency, duration): same as beep, but doesn't pause the computer's output.
There are more, but these are the important ones. You can have a look for yourself and see how the unit works - just open it in Delphi.