[curses]: detecting modifier keys?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MackS

    [curses]: detecting modifier keys?

    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

  • Dennis Lee Bieber

    #2
    Re: [curses]: detecting modifier keys?

    On 10 Nov 2005 01:00:57 -0800, "MackS" <mackstevenson@ hotmail.com>
    declaimed the following in comp.lang.pytho n:
    [color=blue]
    > 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).
    >[/color]
    <ctrl-q> and, I suspect, <ctrl-s> are probably being trapped by the
    console handler itself... Those were commonly used to stop and start
    terminal output -- useful when a program is running up a massive list of
    data and one needs to pause the display to read some of it.

    You might also be losing <ctrl-r>; some systems used that to
    "retype" the command line (back in the days of decwriters, when
    backspace corrections resulted in such stuff as:
    $ typo-comm/mmoc-o/e-command<ctrl-r>
    $ type-command_

    Don't know if there are settings for Windows to turn a console into
    "raw" mode...
    --[color=blue]
    > =============== =============== =============== =============== == <
    > wlfraed@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
    > wulfraed@dm.net | Bestiaria Support Staff <
    > =============== =============== =============== =============== == <
    > Home Page: <http://www.dm.net/~wulfraed/> <
    > Overflow Page: <http://wlfraed.home.ne tcom.com/> <[/color]

    Comment

    • MackS

      #3
      Re: : detecting modifier keys?

      Hi Dennis,

      Thanks for your help, what is happening is clear now. Just found that
      calling curses.raw() lets you get all scan codes.

      Cheers

      Mack

      Comment

      Working...