newLISP Fan Club

Forum => newLISP newS => Topic started by: cormullion on March 07, 2007, 10:24:05 AM

Title: read-key timeout?
Post by: cormullion on March 07, 2007, 10:24:05 AM
Is there a way of calling read-key so that if nothing is read for a certain time - eg a half-second - it completes?
Title:
Post by: Lutz on March 07, 2007, 01:30:18 PM
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.
Title:
Post by: cormullion on March 08, 2007, 09:16:36 AM
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... :-)