/* * Key Downs * --------- * This example shows how to handle keyboard events from * the user. It creates a window with a drawing area on it * which can be used to catch the keyboard events, and it * displays those chars on the drawing area. */ #include #include 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(); }