Do something until keypress

P

Peter Szinek

Hello,

I would like to emulate the good old Pascal 'loop until keypressed' code
snippet:

repeat
write("Hello");
until keypressed;

(also the borland c/c++ function kbhit() was similar).
Also I would like to continue the loop in the same manner unless the
user pressed a specific key.

Since ansi C/C++ does not support this functionality, I guess it is not
supported by Ruby either - and after searching around a bit I could not
find some good substitute yet.

I do no want a general solution - it is enough if it will run under
linux. It is also not a problem if it will require a gem or anything
else (like libcurses-ruby or something).

Any ideas?

TIA
 
J

Jan Svitok

Hello,

I would like to emulate the good old Pascal 'loop until keypressed' code
snippet:

repeat
write("Hello");
until keypressed;

(also the borland c/c++ function kbhit() was similar).
Also I would like to continue the loop in the same manner unless the
user pressed a specific key.

Since ansi C/C++ does not support this functionality, I guess it is not
supported by Ruby either - and after searching around a bit I could not
find some good substitute yet.

I do no want a general solution - it is enough if it will run under
linux. It is also not a problem if it will require a gem or anything
else (like libcurses-ruby or something).

Any ideas?

TIA
See previous thread: "Trouble using puts and getc in different threads"
and others.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top