[curses]: detecting modifier keys?

M

MackS

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
 
D

Dennis Lee Bieber

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).
<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...
--
 
M

MackS

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top