read-key timeout?

Started by cormullion, March 07, 2007, 10:24:05 AM

Previous topic - Next topic

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?

Lutz

#1
The following program would work for 'read-line' but not for 'read-key':


#!/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.

cormullion

#2
Quote from: "Lutz"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.


Quote from: "Lutz"
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... :-)