#!/usr/bin/env python2 import curses # initialize curses stdscr = curses.initscr () curses.noecho () stdscr.keypad (1) curses.typeahead (-1) stdscr.scrollok (1) c = 0 stdscr.addstr ("Simple Curses Demo in Python") while c != 27: (y, x) = stdscr.getyx () if c == curses.KEY_UP and y - 1 >= 0: y = y - 1 elif c == curses.KEY_DOWN and y + 1 < curses.LINES - 1: y = y + 1 elif c == curses.KEY_LEFT and x - 1 >= 0: x = x - 1 elif c == curses.KEY_RIGHT and x + 1 < curses.COLS - 1: x = x + 1 elif (c <= 90 and c >= 65) or (c <= 122 and c >= 97): stdscr.addch (c) else: curses.beep () stdscr.move (y, x) c = stdscr.getch () curses.flushinp () # restore screen curses.echo() curses.endwin()