#include "graphics.h"
#include <stdio.h> // Provides sprintf
#include <iostream.h> // Provides cout
void outintxy(int x, int y, int value);
int main( )
{
int i;
char c;
// Initialize the graphics window.
init_window(400, 300);
// Convert some numbers to strings and draw them in graphics window:
outtextxy(10, 10, "Here are some numbers:");
for (i = 10; i <= 100; i += 10)
outintxy(20, i+10, i);
// Get some characters from the keyboard until an X is typed:
outtextxy(20, 130, "Click in this graphics window,");
outtextxy(20, 140, "and then press arrow keys.");
outtextxy(20, 150, "Watch the console window while pressing.");
outtextxy(20, 160, "Press X to exit.");
do
{
c = (char) getch( );
if (c != 0)
cout << "That is ASCII value: " << (int) c << endl;
else
{ // Process one of the special keys:
c = (char) getch( );
switch (c)
{
case KEY_HOME: cout << "Home key." << endl; break;
case KEY_UP: cout << "Up key." << endl; break;
case KEY_PGUP: cout << "PgUp key." << endl; break;
case KEY_LEFT: cout << "Left key." << endl; break;
case KEY_CENTER: cout << "Center key." << endl; break;
case KEY_RIGHT: cout << "Right key." << endl; break;
case KEY_END: cout << "End key." << endl; break;
case KEY_DOWN: cout << "Down key." << endl; break;
case KEY_PGDN: cout << "PgDn key." << endl; break;
case KEY_INSERT: cout << "Insert key." << endl; break;
case KEY_DELETE: cout << "Delete key." << endl; break;
case KEY_F1: cout << "F1 key." << endl; break;
case KEY_F2: cout << "F2 key." << endl; break;
case KEY_F3: cout << "F3 key." << endl; break;
case KEY_F4: cout << "F4 key." << endl; break;
case KEY_F5: cout << "F5 key." << endl; break;
case KEY_F6: cout << "F6 key." << endl; break;
case KEY_F7: cout << "F7 key." << endl; break;
case KEY_F8: cout << "F8 key." << endl; break;
case KEY_F9: cout << "F9 key." << endl; break;
default: cout << "Unknown extended key." << endl;
}
}
} while ((c != 'x') && (c != 'X'));
closegraph( );
}
void outintxy(int x, int y, int value)
{
char digit_string[20];
sprintf(digit_string, "%d", value);
outtextxy(x, y, digit_string);
}