Вот код для чтения нажатых символов в цикле и отображения их кода:
/* we use curses library */
#include <curses.h>
int main(void)
{
/* curses initialization */
initscr();
/* enable pressing arrow key to generate KEY_xxx codes */
keypad(stdscr, TRUE);
/* make getch wait sometime before returning ERR when no key is pressed */
timeout(100);
/* do not display pressed key */
noecho();
while (1)
{
/* read last pressed key */
int ch = getch();
/* if no key was waiting, ignore */
if (ERR == ch)
continue;
/* if UP is pressed... */
if (KEY_UP == ch)
{
/* ...do something with that key */
/* and wait next key pressed */
continue;
}
/* if Q is pressed, exit the loop */
if ('q' == ch)
break;
/* else, display the key code */
mvprintw(2,2,"code get: 0x%x\n", ch);
/* and some refresh can be useful*/
refresh();
}
/* before quitting, disable curses mode */
endwin();
return 0;
}
Компиляция с библиотекой проклятий:
gcc -Wall main.c -lcurses -ocurses-test
Вот и все.