[curses]: detecting modifier keys?

MackS mackstevenson at hotmail.com
Thu Nov 10 10:00:57 CET 2005


Hello

I am writing a small app to learn how to use the curses module. I would
like to know how I can get "composite" key presses, eg, Control+Q.

Currently I am looking at the following code snippet:

import curses.wrapper

def main(stdscr):

    x = 0

    while True:

        key = stdscr.getch()
        stdscr.addstr(x,0 ,str(key))
        x += 1

    return

curses.wrapper(main)


If I press Control+Q, no numerical code shows on screen. Some other key
combinations work (eg, Control+D, Control+A). Using the Alt key always
produces two codes in a row: 27 (I suppose this corresponds to the Alt
key itself) and the code for the (unmodified) key (eg, Alt+A produces
27 97, while A+B produces 27 98).

The tutorial I am following (http://www.amk.ca/python/howto/curses/)
doesn't mention if there is a way to capture all modified key presses.
Can anyone help me detect eg Control+Q?

Thanks for any guidance,

Mack




More information about the Python-list mailing list