# Do something until keypress

**URL:** <https://rubytalk.org/t/do-something-until-keypress/32341>\
**Category:** ruby-talk\
**Created:** [26 October 2006 12:19 UTC](https://rubytalk.org/t/do-something-until-keypress/32341 "2006-10-26T12:19:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Szinek3](https://avatars.discourse-cdn.com/v4/letter/p/ea5d25/32.png) [@Peter\_Szinek3](https://rubytalk.org/u/Peter_Szinek3)\
**Post date:** [26 October 2006 12:19 UTC](https://rubytalk.org/t/do-something-until-keypress/32341/1 "2006-10-26T12:19:35Z")

</div>

Hello,

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

repeat  
&nbsp;&nbsp;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

> **···**
>
> --  
> Peter  
> [http://www.rubyrailways.com](http://www.rubyrailways.com)

---

<div class="post-metadata">

**Author:** ![Jan\_Svitok](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@Jan\_Svitok](https://rubytalk.org/u/Jan_Svitok)\
**Post date:** [26 October 2006 12:40 UTC](https://rubytalk.org/t/do-something-until-keypress/32341/2 "2006-10-26T12:40:03Z")

</div>

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

> **···**
>
> On 10/26/06, Peter Szinek \<peter@rubyrailways.com\> wrote:
> 
> > Hello,
> > 
> > I would like to emulate the good old Pascal 'loop until keypressed' code  
> > snippet:
> > 
> > repeat  
> > &nbsp;&nbsp;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
