[plt-scheme] Non-blocking single character read in DrScheme?

From: Allyn Dimock (dimock at cs.uml.edu)
Date: Tue Sep 28 22:41:37 EDT 2004

I am looking to read a single character from the keyboard in DrScheme.

According to some stuff I saw on the web and in the manual that
read-string-avail!* was supposed to be completely non-blocking.  But,
in DrScheme v207 nothing is read until I press "Enter".  (In MzScheme
things are a bit messier since the first call to my routine returns
immediately, presumably having read the most recent line terminator
typed to the repl loop.  Then subsequent calls wait for a line

Anyway, the following does _not_ immediately return the next character
from the keyboard.  So I need to ask the experts:  How do I read a
single character in non-blocking mode from DrScheme v207?

(define try-to-read-char-nonblocking-doesnt-work
  (let ((s (make-string 1 #\X)))
    (lambda ()
      (define (get-char)
	(if (= 0 (read-string-avail!* s))
	    (get-char)			;should pause a bit
	    (string-ref s 0)))

Thanks for your help.

-- Allyn Dimock

Posted on the users mailing list.