> Is there a way in IDLE to check to see if a key has been pressed without
> blocking? Either cross-platform or otherwise? I'd like to have students
> write code like:
> while not keyPress():
> I was exploring the idlelib.rpc.RPCProxy object at sys.stdin, but didn't
> see anything obvious.
> Any ideas appreciated,
In the IDLE shell you don't have access to any of the Tk events, since
it is run in a separate process. So you can't directly check for
keyboard events. And IDLE doesn't send input to the subprocess until a
code block is finished, so you can't check for single characters in
the input stream.
If you want to use IDLE's event loop, you'll have to write an
extension for this. You can also write something else which binds to
keyboard events, but then you'll have to make sure it gets notified of
the events ( i.e. IDLE doesn't "swallow" them first).
If you run IDLE without a subprocess then you can use its event loop
directly, but that would be ugly.