[Tutor] (no subject)
Tue, 28 Nov 2000 04:17:56 -0800 (PST)
On Mon, 27 Nov 2000, Devansh Dhutia wrote:
> i was wondering if its possible in python to be able to read the keystrokes
> from a keyboard??
> for example, if a user was to input a sequence of numbers or letters, i want
> to be able to display them elsewhere on the screen immediately after the
> user presses a key.
Hello! You can do rudimentary input with the functions:
Here's a sample interpreter session that shows how to use raw_input():
>>> def queryAndGreet():
... name = raw_input("Please enter your name here: ")
... print "Hello", name, "nice to meet you."
Please enter your name here: Devansh
Hello Devansh nice to meet you.
You'll probably want to use raw_input() to read in your strings; input()
has a more specialized purpose.
However, I get the feeling that your question asked for more control over
screen input and output. If you want fine-tuned control over what happens
on the screen, you might want to look at the curses library:
The curses library will let you position characters at any coordinate of
your text screen. You might need to learn a little more Python before
using it, but you'll definitely have some fun with it.
Finally, I wrote some hideously ugly code that works with the curses
library, if you want an example. Take a look here: