how to implement function keys in linux programming
hello!
recently, I try to study program in linux. I have some problems. for example, I want to use a functional key F1, if I enter F1, end the program. else running others. However, in my program, when I enter 'F1', the program doesn't accord with what I expect to. In my program, I use keypad function to respond to the control function, it seems that it doesn't work. To my acknowledge, I don't know why? now I list my program following: /* =======================================*/ #include <ncurses.h> WINDOW *create_newwin(int height, int width, int starty, int startx); void destroy_win(WINDOW *local_win); int main(int argc, char *argv[]) { WINDOW *my_win; int startx, starty, width, height; int ch; initscr(); cbreak(); keypad(stdscr, TRUE); height = 3; width = 10; starty = (LINES - height) / 2; startx = (COLS - width) / 2; printw("Press F1 to exit"); refresh(); my_win = create_newwin(height, width, starty, startx); while((ch = getch()) != KEY_F(1)) { switch(ch) {case KEY_LEFT: destroy_win(my_win); my_win = create_newwin(height, width, starty,--startx); break; case KEY_RIGHT: destroy_win(my_win); my_win = create_newwin(height, width, starty,++startx); break; case KEY_UP: destroy_win(my_win); my_win = create_newwin(height, width, --starty,startx); break; case KEY_DOWN: destroy_win(my_win); my_win = create_newwin(height, width, ++starty,startx); break; default: break; } } endwin(); return 0; } WINDOW *create_newwin(int height, int width, int starty, int startx) { WINDOW *local_win; local_win = newwin(height, width, starty, startx); box(local_win, 0 , 0); wrefresh(local_win); return local_win; } void destroy_win(WINDOW *local_win) { wborder(local_win, ' ', ' ', ' ',' ',' ',' ',' ',' '); wrefresh(local_win); delwin(local_win); } /*================================== */ in this program, when I enter FI,the program didn't stop, and return. unluckily, the same situation appear when I enter LEFT,RIGHT,UP,DOWN key,the program doesn't expect to my desire. please give me some advice, thanks! |
who can help me?
|
All times are GMT -5. The time now is 03:41 PM. |