Convert input to upper case on screen as it is typed

Ben Finney ben+python at benfinney.id.au
Wed Apr 13 23:25:14 EDT 2016


How can my Python program convert the user's keyboard input to upper
case, as though the user has CAPS LOCK enabled?

I want to emulate a program running on a computer which doesn't have any
lower-case letters (i.e. a character set more limited than ASCII).

The text input, typed interactively by the user at the keyboard, should
be forced to upper case in real time as though that's what the user
typed.

The command line interface could use Python's standard ‘cmd’ library, or
something else. The conversion could be done by a custom input stream,
or some other way.

I am not interested in completely re-implementing the
character-by-character input system; for example, I would like to
continue making use of readline if it is available. I only want to
translate the resulting stream as it appears visually and as it comes
into the program.

Especially important is that the interface should appear visibly
indistinguishable from someone actually typing upper case text; the
display should only ever show the user's input as the upper case text
the program will process.

-- 
 \           “It ain't so much the things we don't know that get us in |
  `\    trouble. It's the things we know that ain't so.” —Artemus Ward |
_o__)                                     (1834–1867), U.S. journalist |
Ben Finney




More information about the Python-list mailing list