Single character input without pressing 'Enter'

how can i read input from stdin, char by char, i want to get the
character as soon as it is entered, without having to press ‘Enter’
after each character.

This is a simple way to achieve that. Maybe there are others

def read_char
system “stty raw -echo”
STDIN.getc
ensure
system “stty -raw echo”
end

good luck

Nguyen Huu Bach wrote:

This is a simple way to achieve that. Maybe there are others

def read_char

Save previous state

old = stty -g

system “stty raw -echo”
STDIN.getc
ensure
system “stty #{old}”
end

good luck

Might be better to use Termios or Curses, though.

On Sep 19, 2006, at 11:33 PM, Eero S. wrote:

end

good luck

Might be better to use Termios or Curses, though.

Or use HighLine which handles all these details for you.

James Edward G. II