Show how to link user defined methods to user defined keys.

An example of this is the facility provided by emacs for key bindings.

These key bindings may be application-specific or system-wide; state which you have done.




#!/usr/bin/env python
import curses
 
def print_message():
    stdscr.addstr('This is the message.\n')
 
stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
stdscr.keypad(1)
 
stdscr.addstr('CTRL+P for message or q to quit.\n')
while True:
    c = stdscr.getch()
    if c == 16: print_message()
    elif c == ord('q'): break
 
curses.nocbreak()
stdscr.keypad(0)
curses.echo()
curses.endwin()
 