LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-14-2009, 05:11 AM   #1
michaelhero
LQ Newbie
 
Registered: May 2009
Posts: 2

Rep: Reputation: 0
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!
 
Old 05-15-2009, 06:36 AM   #2
michaelhero
LQ Newbie
 
Registered: May 2009
Posts: 2

Original Poster
Rep: Reputation: 0
who can help me?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Simple Code To Implement C's stat() function On Linux And Unix LXer Syndicated Linux News 0 03-03-2009 06:27 AM
USB keyboard function keys/numeric keys on boot raypen Linux - Hardware 4 04-17-2008 04:07 PM
Function keys not working in Linux for NC8000 wearetheborg Debian 0 10-21-2007 08:35 PM
Programming function keys dazdaz Linux - Software 14 11-04-2003 05:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration