#include "graphapp.h"
#include <ctype.h>
point location = {0,0};
void key_down(drawing d, int key)
{
char letter[2];
int width;
if (! isprint(key))
return;
sprintf(letter, "%c", key);
width = strwidth(FixedFont, letter);
if (location.x + width > getwidth(d)) {
location.x = 0;
location.y += getheight(FixedFont);
}
setfont(FixedFont);
drawstr(location, letter);
location.x += width;
}
void main(void)
{
window w;
drawing d;
w = newwindow("Press a Key", rect(50,50,200,200),
StandardWindow);
d = newdrawing(rect(10,10,180,180), NULL);
setbackground(w, LightGrey);
setkeydown(d, key_down);
show(w);
mainloop();
}