/* http://www.cyut.edu.tw/~ckhung/b/mi/ */
/* 1999-06 */
/* how to compile: gcc -Wall keypad.c -lncurses */

#include <ncurses/curses.h>
#include <stdio.h>

int main()
{
    int width, height;
    int c, x, y;
    int go_on;

    initscr();
    cbreak();
    noecho();
    keypad(stdscr, 1);
    getmaxyx(stdscr, height, width);
    mvaddstr(0, 0, "press arrow keys to move the cursor;");
    mvaddstr(1, 0, "press any other key to quit");
    x = y = 0;
    go_on = 1;
    while (go_on) {
	move(y, x);
	c = getch();
	switch (c) {
	case KEY_LEFT:  --x; break;
	case KEY_RIGHT: ++x; break;
	case KEY_UP:    --y; break;
	case KEY_DOWN:  ++y; break;
	default:	go_on = 0;
	}
	while (x < 0) x += width;
	while (x >= width) x -= width;
	while (y < 0) y += height;
	while (y >= height) y -= height;
    }
    endwin();
    return 0;
}

