Source Code File 08-06_arrowkeys

08-06_arrowkeys.c

#include <ncurses.h>
   
int main()
{
    int ch;
    
    initscr();
    
    keypad(stdscr,TRUE);
    do
    {
        ch = getch();
        switch(ch)
        {
            case KEY_DOWN:
                addstr("Down\n");
                break;
            case KEY_UP:
                addstr("Up\n");
                break;
            case KEY_LEFT:
                addstr("Left\n");
                break;
            case KEY_RIGHT:
                addstr("Right\n");
            default:
                break;
        }
        refresh();
    } while(ch != '\n');
    
    endwin();
    return(0);
}

Output Screenshot

Notes

* If you don't see any output, try pressing the NumLock key on the keyboard.