Keys To The Kingdom

Tim Hammerquist tim at vegeta.ath.cx
Sun Jul 8 20:46:34 EDT 2001


On 09 Jul 2001 00:14:11 GMT, Tim Daneliuk <tundra at tundraware.com> wrote:
> I have a two part question about accepting keyboard input in python:
> 
> Is there a standard way to read one keystroke at a time rather than
> doing line input via raw_input()?
> 
> For some reason, I cannot seem to catch Ctrl-C when it is typed in response
> to a raw_input() call.  This code still blows out of the python interpreter
> when the user keys in Ctrl-C:
> 
> try:
> 	x=raw_input()
> except KeyBoardInterrupt:
> 	# Handle the Ctrl-C and regroup
>         ...

This works for me:

    try:
        input = raw_input()
    except KeyboardInterrupt:
        # handle Ctrl-C

The only difference I see is the capital 'B' you have in
'KeyboardInterrupt'.  Change it to lowercase and see what happens.

HTH
-- 
-Tim Hammerquist <timmy at cpan.org>
Never put off until tomorrow that
which can be done the day after tomorrow.
    -- Mark Twain



More information about the Python-list mailing list