/* * Ejemplo inútil de uso de ncurses * * Jorge López, 2004-04-29 * * compilación: gcc -lncurses -o teclas teclas.c * */ #include #include int main(void) { int tecla; WINDOW *ventana1, *ventana2; initscr(); start_color(); init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_YELLOW, COLOR_BLACK); init_pair(3, COLOR_BLUE, COLOR_BLACK); init_pair(4, COLOR_GREEN, COLOR_BLACK); noecho(); /* ventana1: donde saldrán los mensajes */ ventana1= newwin(10, 80, 0, 0); /* Ventana en (0,0) de 80x10 */ ventana2= newwin(12, 80, 11, 0); /* Ventana en (0,11) */ keypad(ventana2, TRUE); /* Leemos teclas en ventana2 */ mvwprintw(ventana1, 1, 2, "Venga, pulsa teclas de dirección! Con F1 " \ "saldrás\n"); /* Borde para la ventana1 */ //wborder(ventana1, 'i', 'i', '-', '-', '+','+','+','+'); wrefresh(ventana1); while ((tecla = wgetch(ventana2))!=KEY_F(1)) { switch (tecla) { case KEY_UP: wattron(ventana1, COLOR_PAIR(1)); wprintw(ventana1, "^"); wattroff(ventana1, COLOR_PAIR(1)); break; case KEY_DOWN: wattron(ventana1, COLOR_PAIR(2)); wprintw(ventana1, "_"); wattroff(ventana1, COLOR_PAIR(2)); break; case KEY_LEFT: wattron(ventana1, COLOR_PAIR(3)); wprintw(ventana1, "<"); wattroff(ventana1, COLOR_PAIR(3)); break; case KEY_RIGHT: wattron(ventana1, COLOR_PAIR(4)); wprintw(ventana1, ">"); wattroff(ventana1, COLOR_PAIR(4)); break; default: wattron(ventana2, A_BOLD); wprintw(ventana2, "Me da a mí que eso no es una tecla de " \ "dirección...\n"); wattroff(ventana2, A_BOLD); } wrefresh(ventana1); wrefresh(ventana2); } endwin(); return 0; }