Page 1 of 1

read-key timeout?

Posted: Wed Mar 07, 2007 6:24 pm
by cormullion
Is there a way of calling read-key so that if nothing is read for a certain time - eg a half-second - it completes?

Posted: Wed Mar 07, 2007 9:30 pm
by Lutz
The following program would work for 'read-line' but not for 'read-key':

Code: Select all

#!/usr/bin/newlisp

(print "Enter something:")
(set 'cnt 0)
(while (and (= (peek 0) 0) (< cnt 50)) (sleep 100) (inc 'cnt))
(if (< cnt 50) 
        (println "User entered: " (read-line))
        (println "nothing was entered"))

(exit)
The loop exits when something is entered or 5 seconds have passed.

Of course this would work only on MacOS X and UNIX. There may be a better solution working on individual keystrokes via importing some functions from the curses library?

Lutz

ps: I am not available on this board all Thursday (travelling).
pps: please post only news and documentation stuff in the news section.

Posted: Thu Mar 08, 2007 5:16 pm
by cormullion
Lutz wrote:The following program would work for 'read-line' but not for 'read-key':
Pity - I'm looking for a way to see if a key is being pressed, but if it isn't, continuing on.
Lutz wrote: pps: please post only news and documentation stuff in the news section.
OK - trouble is, I keep seeing "newlisp talk in general" and posting there... :-)