/* * Keybord Events * -------------- * This program prints out messages for many kinds of * keyboard events. It handles both normal ASCII keys * and other kinds of keyboard events, such as arrow * keys, function keys, page-up, page-down, home, etc. */ #include #include void handle_keydown(drawing d, int key) { if (isprint(key)) printf("Key: %c", key); else if (key == BKSP) printf("Backspace"); else if (key == ESC) printf("Escape"); else if (key == '\t') printf("Tab"); else if (key == '\n') printf("Newline"); else printf("Non-printable ASCII key"); printf("\n"); } void handle_keyaction(drawing d, int key) { if (key == ENTER) printf("Enter"); else if (key == HOME) printf("Home"); else if (key == END) printf("End"); else if (key == PGUP) printf("Page Up"); else if (key == PGDN) printf("Page Down"); else if (key == INS) printf("Insert"); else if (key == DEL) printf("Delete"); else if (key == LEFT) printf("Left Arrow"); else if (key == RIGHT) printf("Right Arrow"); else if (key == UP) printf("Up Arrow"); else if (key == DOWN) printf("Down Arrow"); else if ((key >= F1) && (key <= F9)) printf("Function key %c", (key - F1 + '1')); else if (key == F10) printf("Function key 10"); printf("\n"); } void main(void) { window w; drawing d; w = newwindow("Use the Mouse", rect(50,50,200,200), StandardWindow); d = newdrawing(rect(10,10,180,180), NULL); setbackground(w, LightGrey); setkeydown(d, handle_keydown); setkeyaction(d, handle_keyaction); show(w); mainloop(); }