From: David J. Steele
Subject: Use of LISTEN or READ-CHAR-NO-HANG for Testing Keyboard Input
Date:
Message-ID: <6vcdn5$qck$1@mawar.singnet.com.sg>
Wonder if somebody can help me with the following problem:
I am working on a project for man-machine conversational
dialogue, and would like to be able to test for keyboard input
from the user such that, if the user has not responded within
x seconds, the machine would issue another prompt. It seems
to me that one ought to be able to use either LISTEN or READ-
CHAR-NO-HANG to test whether a character has been input
to the keyboard as *st andard-input*. I tried a test program
along the following lines:
(defun test-listen (&aux init sum next char input) ;Notes
(setf init (car (multiple-value-list (get-decoded-time))) ;01
sum 0)
(loop
(setf next (car (multiple-value-list (get-decoded-time)))) ;02
(cond
((setf char
(read-char-no-hang *standard-input* nil nil))
;03
(format t
;04
"~%Character ~a read from console after ~a seconds" char sum)
(unread-char char)
;05
(setf input (read-line))
;06
(format t
;07
"~%Input = ~a" input)
(return))
;08
(t (when (not (eq next init))
;09
(setf sum (1+ sum)
init next)
(format t
"~%Another second elapsed; sum = ~a" sum)))))) ;10
;Notes
;01 Initialise start of time measurement
;02 Get current time
;03 Is character available from the console?
;04 If so, print message as to time elapsed
;05 Push character back onto the front of the input stream
;06 Read input typed into the keyboard
;07 Confirm input read by (read-line)
;08 Return from loop and exit test function
;09 Otherwise, increment time at next even second elapsed
;10 Print message as to total time elapsed
but when I run it (or a similar version structured for LISTEN) keyboard
input is completely ignored and the program just keeps counting the
seconds. What am I doing wrong? I am using ACL Version 3.0.1.
Regards,
Dave Steele
In article <············@mawar.singnet.com.sg>,
David J. Steele <········@singnet.com.sg> wrote:
>but when I run it (or a similar version structured for LISTEN) keyboard
>input is completely ignored and the program just keeps counting the
>seconds. What am I doing wrong? I am using ACL Version 3.0.1.
If this is on Unix, the terminal driver is normally in line-at-a-time
mode. Unless you've used a system-specific function to change to character
mode, neither LISTEN nor READ-CHAR-NO-HANG will detect characters available
until you hit RETURN, since the tty driver doesn't make them available to
the application until then.
--
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.