read-key timeout?

Notices and updates
Locked
cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

read-key timeout?

Post 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?

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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.

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post 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... :-)

Locked