# Do something until keypress

**URL:** <https://www.ruby-forum.com/t/do-something-until-keypress/73704>\
**Category:** Ruby\
**Created:** [October 26, 2006, 2:19pm UTC](https://www.ruby-forum.com/t/do-something-until-keypress/73704 "2006-10-26T14:19:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![splattael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@splattael](https://www.ruby-forum.com/u/splattael)\
**Post date:** [October 26, 2006, 2:19pm UTC](https://www.ruby-forum.com/t/do-something-until-keypress/73704/1 "2006-10-26T14:19:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![splattael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@splattael](https://www.ruby-forum.com/u/splattael)\
**Post date:** [October 26, 2006, 2:41pm UTC](https://www.ruby-forum.com/t/do-something-until-keypress/73704/2 "2006-10-26T14:41:54Z")

</div>

On 10/26/06, Peter S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Also I would like to continue the loop in the same manner unless the  
> Any ideas?
> 
> TIA

See previous thread: “Trouble using puts and getc in different threads”  
and others.
