Quantcast

non-blocking getch() or kbhit() in IDLE

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

non-blocking getch() or kbhit() in IDLE

Doug Blank-3
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():
     robot.forward(1)
     wait(.1)

I was exploring the idlelib.rpc.RPCProxy object at sys.stdin, but didn't
see anything obvious.

Any ideas appreciated,

-Doug
_______________________________________________
IDLE-dev mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/idle-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: non-blocking getch() or kbhit() in IDLE

Tal Einat
On 9/5/07, Douglas S. Blank <[hidden email]> wrote:

> 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():
>      robot.forward(1)
>      wait(.1)
>
> I was exploring the idlelib.rpc.RPCProxy object at sys.stdin, but didn't
> see anything obvious.
>
> Any ideas appreciated,
>
> -Doug

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.

- Tal
_______________________________________________
IDLE-dev mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/idle-dev
Loading...