Hi,

Am Donnerstag, 04. Sep 2008, 05:40:43 +0900 schrieb Kenneth McDonald:
> In the following bit of code:
>
> print STDIN.getc
> STDOUT.flush
>
> The code for whatever key I type isn't actually printed out until I go on 
> to hit the return key. How can I have it printed as soon as I type a 
> character key?

On feasible operating systems you can install the "termios" gem.
Then say something like:

  class IO
    def nocanon
      term = Termios::getattr self
      term.c_lflag &= ~Termios::ICANON
      Termios::setattr self, Termios::TCSANOW, term
      yield
    ensure
      term.c_lflag |= Termios::ICANON
      Termios::setattr self, Termios::TCSANOW, term
    end
  end

  $stdin.nocanon do
    c = $stdin.getc
  end

Maybe you like to have a look at how I let the user enter
passwords: <http://bertram-scharpf.homelinux.com/src/password.rb>.

Good luck!

Bertram


-- 
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de